Skip to content

fix(policy): resolve circular import blocking package import#62

Open
Rehan30g wants to merge 1 commit into
Forebase:mainfrom
Rehan30g:fix/policy-engine-circular-import
Open

fix(policy): resolve circular import blocking package import#62
Rehan30g wants to merge 1 commit into
Forebase:mainfrom
Rehan30g:fix/policy-engine-circular-import

Conversation

@Rehan30g

Copy link
Copy Markdown

Summary

redactable.policy.engine imports Policy back from redactable.policy, but redactable/policy/__init__.py imports engine before it gets to defining/importing Policy itself. That circular reference means import redactable currently raises:

ImportError: cannot import name 'Policy' from partially initialized module 'redactable.policy' (most likely due to a circular import)

This isn't a corner case — it fails on a plain import redactable, and it was blocking pytest from even collecting test_apply.py, test_policy_engine.py, test_policy_loader.py, and test_transforms.py.

Fix

Import Policy directly from redactable.policy.model (where it's actually defined) instead of re-importing it through the package __init__.

Type

  • Bug fix

Testing

  • import redactable now succeeds.
  • pytest tests/test_apply.py tests/test_policy_loader.py tests/test_transforms.py — all pass (these previously failed to even collect).
  • ruff check src/redactable/policy/engine.py — clean.
  • mypy src/redactable/policy/engine.py — clean.

Note: a few unrelated tests (test_detectors.py, test_pandas_integration.py, test_policy_engine.py's audit-event tests) fail for separate, pre-existing reasons (e.g. datetime.utcnow() deprecation warnings promoted to errors, and Finding attribute mismatches) that were previously masked by the collection error. Left those out of scope to keep this fix focused and easy to review.

Checklist

  • Tests added/updated (existing regression coverage now actually runs)
  • Docs updated (not applicable, internal import fix)
  • Pre-commit hooks passed locally
  • Lint/typecheck passed (ruff, mypy)
  • Backwards compatible
  • Changelog entry added

engine.py imported Policy back from the redactable.policy package
init, which itself imports engine at load time. That made
`import redactable` (and the whole test suite) fail with an
ImportError before anything could run. Import Policy from
policy.model directly instead.
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.

1 participant