Skip to content

fix: skip pattern matching in delete_link when no matching func is set - #436

Closed
vlieven wants to merge 3 commits into
apache:masterfrom
vlieven:fix/delete-link-skip-matching-without-func
Closed

vlieven wants to merge 3 commits into
apache:masterfrom
vlieven:fix/delete-link-skip-matching-without-func

Conversation

@vlieven

@vlieven vlieven commented Sep 24, 2026

Copy link
Copy Markdown

RoleManager.add_link only walks all_roles to apply pattern-derived links when a matching function is set, but delete_link walked it unconditionally. With matching_func = None, every iteration called match_error_handler(None, ...), which raised and swallowed a TypeError, so the result was correct but each delete was O(roles) wasted work.

The cost multiplies with a domain matching function on g (e.g. g, user, group, * with key_match), because DomainManager forwards the delete to every cached domain's role manager.

Guard the loop with the same check add_link uses. ConditionalRoleManager, DomainManager and ConditionalDomainManager all delegate to this method, so they are covered too.
Add tests that check delete_link behavior without a matching function, both on its own and across cached domains.
Also correct != None to is not None (PEP8)

vlieven added 3 commits September 24, 2026 10:12
RoleManager.add_link only walks all_roles to apply pattern-derived links
when a matching function is set, but delete_link walked it
unconditionally. With matching_func = None, every iteration called
match_error_handler(None, ...), which raised and swallowed a TypeError,
so the result was correct but each delete was O(roles) wasted work.

The cost multiplies with a domain matching function on g (e.g.
`g, user, group, *` with key_match), because DomainManager forwards the
delete to every cached domain's role manager.

Guard the loop with the same check add_link uses. ConditionalRoleManager,
DomainManager and ConditionalDomainManager all delegate to this method,
so they are covered too. Add tests that check delete_link behavior
without a matching function, both on its own and across cached domains.
RoleManager.add_link only walks all_roles to apply pattern-derived links
when a matching function is set, but delete_link walked it
unconditionally. With matching_func = None, every iteration called
match_error_handler(None, ...), which raised and swallowed a TypeError,
so the result was correct but each delete was O(roles) wasted work.

The cost multiplies with a domain matching function on g (e.g.
`g, user, group, *` with key_match), because DomainManager forwards the
delete to every cached domain's role manager.

Guard the loop with the same check add_link uses. ConditionalRoleManager,
DomainManager and ConditionalDomainManager all delegate to this method,
so they are covered too. Add tests that check delete_link behavior
without a matching function, both on its own and across cached domains.
@hsluoyz

hsluoyz commented Sep 24, 2026

Copy link
Copy Markdown
Member

replaced by: b7c36d9

@hsluoyz hsluoyz closed this Sep 24, 2026
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 35975753290

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Coverage decreased (-0.05%) to 84.172%

Details

  • Coverage decreased (-0.05%) from the base build.
  • Patch coverage: 1 uncovered change across 1 file (9 of 10 lines covered, 90.0%).
  • 2 coverage regressions across 1 file.

Uncovered Changes

File Changed Covered %
casbin/rbac/default_role_manager/role_manager.py 10 9 90.0%

Coverage Regressions

2 previously-covered lines in 1 file lost coverage.

File Lines Losing Coverage Coverage
casbin/rbac/default_role_manager/role_manager.py 2 91.97%

Coverage Stats

Coverage Status
Relevant Lines: 3955
Covered Lines: 3329
Line Coverage: 84.17%
Coverage Strength: 5.05 hits per line

💛 - Coveralls

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.

3 participants