-
-
Notifications
You must be signed in to change notification settings - Fork 210
feat: fix inconsistent async handling bug for watcher.update() API #406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
|
Co-authored-by: hsluoyz <[email protected]>
Co-authored-by: hsluoyz <[email protected]>
|
@1812526510 can you check if this PR resolved your issue? |
|
up, I was suffering from this issue and provided a fix in this PR : cc @hsluoyz |
|
@devamin https://github.com/pycasbin/casbin is NOT the official repo from Casbin team. The official repo is this repo: https://github.com/casbin/pycasbin. You need to create PR in this repo. |
|
@hsluoyz Thanks for the fix! Confirmed it’s working on my side |
|
@1812526510 which fix? Give a link? |
|
@hsluoyz The code in the branch copilot/fix-inconsistent-async-handling fixed my issue. |
# [2.4.0](v2.3.0...v2.4.0) (2025-10-14) ### Features * fix inconsistent async handling bug for watcher.update() API ([#406](#406)) ([7875d02](7875d02))
|
🎉 This PR is included in version 2.4.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Problem
In
AsyncInternalEnforcer, there was an inconsistency in how watcher methods were handled. While specialized watcher methods likeupdate_for_add_policywere properly checked for being coroutine functions and awaited when necessary, the fallbackwatcher.update()method was called directly without any async checking.Example of the issue:
This caused "coroutine was never awaited" warnings when using async watchers that implement only the base
update()method without specialized methods. The watcher would not be properly notified of policy changes.Solution
Applied consistent async handling to all
watcher.update()calls by checking if the method is a coroutine function before calling it:This pattern was applied to 10 locations across the following methods:
save_policy()- fallback case_add_policy()- fallback case_add_policies()- fallback case_update_policy()- direct call_update_policies()- direct call_update_filtered_policies()- direct call_remove_policy()- fallback case_remove_policies()- fallback case_remove_filtered_policy()- fallback case_remove_filtered_policy_returns_effects()- direct callTesting
Added comprehensive test coverage with:
AsyncMinimalWatcher- a minimal async watcher that only implements the asyncupdate()methodtest_async_minimal_watcher()- validates that all policy operations properly await async watchersAll 301 tests pass with no warnings about unawaited coroutines.
Benefits
Fixes inconsistent async handling as described in the related issue.
Original prompt
Fixes #405
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.