Skip to content

Bug: Fix circular import #141

@MaferMazu

Description

@MaferMazu

Description

When we add from openedx_authz.engine.matcher import is_admin_or_superuser_check in openedx_authz/engine/enforcer.py, we create a circular import issue: enforcer → matcher → api → permissions → enforcer, so when I tried to run ./manage lms load_policy or from openedx_authz.engine.enforcer import AuthzEnforcer in the shell, I get:

from openedx_authz.engine.enforcer import AuthzEnforcer
  File "/openedx/openedx-authz/openedx_authz/engine/enforcer.py", line 25, in <module>
    from openedx_authz.engine.matcher import is_admin_or_superuser_check
  File "/openedx/openedx-authz/openedx_authz/engine/matcher.py", line 5, in <module>
    from openedx_authz.api.data import ContentLibraryData, ScopeData, UserData
  File "/openedx/openedx-authz/openedx_authz/api/__init__.py", line 9, in <module>
    from openedx_authz.api.permissions import *
  File "/openedx/openedx-authz/openedx_authz/api/permissions.py", line 9, in <module>
    from openedx_authz.engine.enforcer import AuthzEnforcer
ImportError: cannot import name 'AuthzEnforcer' from partially initialized module 'openedx_authz.engine.enforcer' (most likely due to a circular import) (/openedx/openedx-authz/openedx_authz/engine/enforcer.py)

How to reproduce the error

Running Load Policy:

  1. Use the last version of openedx-authz and try to run ./manage lms load_policy.
  2. Get an import error.

Simpler:

  1. Enter shell ./manage lms shell
  2. Import AuthzEnforcer from openedx_authz.engine.enforcer import AuthzEnforcer

Remotly:

With the #143 I add a test, and without the fix it fail:
You can also see it failing here: https://github.com/eduNEXT/openedx-authz/actions/runs/19317767166/job/55252613927?pr=2

Expected behavior

Be able to run the ./manage lms load_policy withouth problems.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions