Skip to content

[BUG] Auth Schema bug #132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
vlada1g opened this issue May 14, 2025 · 1 comment
Open

[BUG] Auth Schema bug #132

vlada1g opened this issue May 14, 2025 · 1 comment

Comments

@vlada1g
Copy link

vlada1g commented May 14, 2025

<ContextVar name='ROUTE_CONTEXT_VAR' at 0xffff945f79c0>
Traceback (most recent call last):
  File "/opt/venv/lib/python3.11/site-packages/ninja/operation.py", line 132, in run
    values = self._get_values(request, kw, temporal_response)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.11/site-packages/ninja/operation.py", line 309, in _get_values
    data = model.resolve(request, self.api, path_params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.11/site-packages/ninja/params/models.py", line 68, in resolve
    return cls.model_validate(data, context={"request": request})
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.11/site-packages/pydantic/main.py", line 703, in model_validate
    return cls.__pydantic_validator__.validate_python(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.11/site-packages/ninja/schema.py", line 225, in _run_root_validator
    handler(values)
  File "/opt/venv/lib/python3.11/site-packages/ninja_jwt/schema.py", line 131, in validate_inputs
    request = schema_input.get_request()
              ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.11/site-packages/ninja_jwt/schema.py", line 37, in get_request
    return service_resolver(RouteContext).request
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.11/site-packages/ninja_extra/dependency_resolver.py", line 38, in service_resolver
    return injector.get(interfaces[0])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.11/site-packages/injector/__init__.py", line 91, in wrapper
    return function(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.11/site-packages/injector/__init__.py", line 977, in get
    result = provider_instance.get(self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.11/site-packages/injector/__init__.py", line 302, in get
    return injector.call_with_injection(self._callable)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.11/site-packages/injector/__init__.py", line 1050, in call_with_injection
    return callable(*full_args, **dependencies)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.11/site-packages/ninja_extra/modules.py", line 31, in <lambda>
    binder.bind(RouteContext, to=lambda: self.get_route_context())  # type: ignore
                                         ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/venv/lib/python3.11/site-packages/ninja_extra/modules.py", line 27, in get_route_context
    return ROUTE_CONTEXT_VAR.get()
           ^^^^^^^^^^^^^^^^^^^^^^^
LookupError: <ContextVar name='ROUTE_CONTEXT_VAR' at 0xffff945f79c0>

We got this error on the latest Version, when we switch back to 5.3.5 the error is not shown any more.
Below is the endpoint definition.

@auth_router.post(
    "/token/pair",
    response=AlohaTokenObtainPairOutSchema,
    auth=None,
    tags=["auth"]
)
def obtain_token(request, user_token: AlohaTokenObtainPairInputSchema = Form(...)):
@vlada1g vlada1g changed the title Auth Schema bug [BUG] Auth Schema bug May 14, 2025
@scotu
Copy link

scotu commented May 14, 2025

@vlada1g check if you are using the regular django ninja Router or NinjaAPI and if so, replace them with the django ninja extra equivalents. I remember I was doing this a couple of days ago and got the same error

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

No branches or pull requests

2 participants