Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 6, 2025

enforce_ex returns empty explanation arrays for allow decisions when using models with explicit deny rules (e.g., rbac_with_deny_model).

import casbin
e = casbin.Enforcer("examples/rbac_with_deny_model.conf", "examples/rbac_with_deny_policy.csv")
e.enforce_ex("alice", "data2", "read")
# Before: (True, [])
# After:  (True, ['data2_admin', 'data2', 'read', 'allow'])

Changes

  • core_enforcer.py: Update explain_index for every matching policy, not just when intermediate effect triggers early break. AllowAndDenyEffector.intermediate_effect() returns INDETERMINATE for allow-only cases (must scan all policies for deny), preventing explain_index from being set.

  • test_enforcer.py: Add test_enforce_ex_rbac_with_deny to verify explanations are returned for both allow and deny cases.

Original prompt

This section details on the original issue you should resolve

<issue_title>Not explaining with deny</issue_title>
<issue_description>```python

import casbin
e = casbin.Enforcer("examples/rbac_with_deny_model.conf", "examples/rbac_with_deny_policy.csv")
e.enforce_ex("alice", "data2", "read")
(True, [])


It should not be `[]`, should have data.</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
@hsluoyz hsluoyz marked this pull request as ready for review November 6, 2025 11:59
Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix enforcement logic for deny scenarios Fix enforce_ex returning empty explanations for allow rules in deny models Nov 6, 2025
Copilot AI requested a review from hsluoyz November 6, 2025 12:03
Copilot finished work on behalf of hsluoyz November 6, 2025 12:03
@hsluoyz hsluoyz closed this Nov 6, 2025
@hsluoyz hsluoyz reopened this Nov 6, 2025
@hsluoyz hsluoyz changed the title Fix enforce_ex returning empty explanations for allow rules in deny models feat: fix enforce_ex() API returning empty explanations for allow rules in deny models Nov 6, 2025
@hsluoyz hsluoyz merged commit a2c5fcc into master Nov 6, 2025
25 of 27 checks passed
hsluoyz added a commit that referenced this pull request Nov 6, 2025
github-actions bot pushed a commit that referenced this pull request Nov 6, 2025
# [2.6.0](v2.5.0...v2.6.0) (2025-11-06)

### Features

* fix enforce_ex() API returning empty explanations for allow rules in deny models ([#412](#412)) ([dbd28b7](dbd28b7))
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.

Not explaining with deny

3 participants