Skip to content

Conversation

jdiego
Copy link
Contributor

@jdiego jdiego commented Sep 4, 2025

Closes #287

Updated NinjaExtraAPI.register_controllers to handle per-API isolation:

  • If a controller is already registered globally, create a cloned subclass
    and a fresh APIController to avoid shared global state.
  • Added _registered_controllers (WeakSet) to guard against duplicate registration on the same API.
  • Added _controller_clones (dict) to cache per-API clones and prevent creating multiple subclasses for the same original controller.
  • Ensure API instance is bound before building routers so PathViews register under the correct API context.

Enhanced tests:

  • Verified controllers bind operations to the correct API.
  • Ensured auto_discover_controllers respects auto_import=False.
  • Asserted duplicate registration on the same API is a no-op.
  • Verified same controller can be mounted on multiple APIs with isolation
    (distinct routers, correct self.api binding).
  • Confirmed OpenAPI schemas are consistent across multiple APIs.
  • Added regression test for clone caching to prevent duplicate clones.

@codecov-commenter
Copy link

codecov-commenter commented Sep 4, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.02%. Comparing base (6a592c1) to head (fea0798).
⚠️ Report is 20 commits behind head on master.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #293   +/-   ##
=======================================
  Coverage   98.01%   98.02%           
=======================================
  Files          68       68           
  Lines        2770     2834   +64     
=======================================
+ Hits         2715     2778   +63     
- Misses         55       56    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@eadwinCode
Copy link
Owner

eadwinCode commented Sep 8, 2025

@jdiego Nice work here. Thanks.
I think we need to a add an INFO log when we are cloning the controllers for another API instance. This is important, so that devs are aware that the controller was cloned and they want this set of behaviours. Also, it will be good for debugging

@jdiego
Copy link
Contributor Author

jdiego commented Sep 20, 2025

@eadwinCode done.

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.

Problem: Controller can't be registered in multiple NinjaExtraAPI instances
3 participants