Skip to content

Conversation

@devamin
Copy link

@devamin devamin commented Oct 12, 2025

Why

I was trying to use casbin-async-postgres-watcher with an AsyncEnforcer, and it appears that the enforcer watcher update call was sync, but the async-postgres-watcher is async, warned by the following

/Users/amin/Library/Caches/pypoetry/virtualenvs/uchat-oa-backend-dVRSYrvN-py3.12/lib/python3.12/site-packages/casbin/async_internal_enforcer.py:164: RuntimeWarning: coroutine 'AsyncPostgresWatcher.update' was never awaited
  self.watcher.update()
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

What

I decided to refactor the AsyncInternalEnforcer to handle update in case of an async definition, while doing this I found out that I can reduce some code duplications.

To Reproduce

pseudo-snippet

from casbin.async_enforcer import AsyncEnforcer
from async_postgres_watcher import AsyncPostgresWatcher
from casbin.persist.adapters import FileAdapter

casbin_enforcer = AsyncEnforcer(adapter)

watcher = AsyncPostgresWatcher(host=HOST, port=PORT, user=USER, password=PASSWORD, dbname=DBNAME)
watcher.set_update_callback(casbin_enforcer.e.load_policy)

casbin_enforcer.set_watcher(watcher)

@CLAassistant
Copy link

CLAassistant commented Oct 12, 2025

CLA assistant check
All committers have signed the CLA.

@devamin devamin changed the title feat: resume the watcher update into a single private method, manage … handle watcher .update() in case of async definition Oct 13, 2025
@devamin devamin changed the title handle watcher .update() in case of async definition fix: handle watcher .update() in case of async definition Oct 13, 2025
@devamin devamin closed this Oct 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants