-
-
Notifications
You must be signed in to change notification settings - Fork 567
Description
Describe the bug
Starting with 1.6.0 release, it is not possible anymore to retrieve Operation or the NinjaAPI instance from the endpoint function.
Versions (please complete the following information):
- Python version: 3.14
- Django version: 5.2.12
- Django-Ninja version: 1.6.0, 1.6.1
- Pydantic version: 2.12.5
More context
I work on a product providing arount 500 REST endpoints. We recently finished to switch from a legacy system to django-ninja in order to define and document our endpoints.
We implemented a custom decorator that we used above @router.post() to configure each endpoint. In this decorator, we previously used getattr(endpoint, "_ninja_operation") to retrieve the Operation instance initialized by django-ninja and attached to the function via the _ninja_operation attribute. This object helped us to retrieve the current NinjaAPI instance and perform additional configuration on generated OpenAPI structure, etc.
Unfortunately, since 1.6.0 and the new "Idempotent Router", it is not possible anymore. An Operation object is still attached to the function, but this one does not have any link to NinjaAPI instance. This is because now, BoundRouter._bind_operations() clone the PathView and the related operations before setting operation.api to the current api instance.
As a result, the Operation instance linked to the function (func._ninja_operation) is incomplete and I can't find a documented way to retreieve the API instance from any endpoint function.
I understand that could be difficult because a single endpoint can now be linked to multiple API through a single "idempotent" router, but it could be very useful to have a proper way to get the NinjaAPI or Operation instance for a given function.
Best regards