Skip to content
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

Failed to load API definition - /api/docs #66

Open
jankrnavek opened this issue Jun 8, 2023 · 14 comments
Open

Failed to load API definition - /api/docs #66

jankrnavek opened this issue Jun 8, 2023 · 14 comments

Comments

@jankrnavek
Copy link

On /api/docs endpoint i get this html error.

Python version: 3.11.3
Django version: 4.2.2
Django-Ninja version: 0.22.1
Django-Ninja-Extra 0.18.9

With previous version everthing works fine.
(Django-Ninja version: 0.21.x, Django-Ninja-Extra 0.18.8)

Failed to load API definition.
Errors
Fetch error
Internal Server Error /api/openapi.json
@jankrnavek
Copy link
Author

The above problem is fixed, please update your package to support the latest django-ninja.
Thnak you.

@eadwinCode
Copy link
Owner

Awesome stuff

@jankrnavek
Copy link
Author

Everything works alright.
Thank you.

@jankrnavek
Copy link
Author

jankrnavek commented Jun 9, 2023

Hello @eadwinCode ,
one more note your django-ninja-jwt = "5.2.5" doens't work as well, "5.2.2" is OK

@eadwinCode
Copy link
Owner

@jankrnavek can you be more specific to what you mean by doesn't work?

@jankrnavek
Copy link
Author

Poetry update output:

(mabb-py3.11) PS C:\git\mabb> poetry update
Updating dependencies
Resolving dependencies...

Package operations: 0 installs, 1 update, 3 removals

  • Removing dnspython (2.3.0)
  • Removing email-validator (2.0.0.post2)
  • Removing ninja-schema (0.13.0)
  • Updating django-ninja-jwt (5.2.2 -> 5.2.5)

Writing lock file

Errors in log after restarting Gunicorn:

Traceback (most recent call last):
  File "/home/webhosting/mabb/env/lib/python3.11/site-packages/django/template/base.py", line 890, in _resolve_lookup
    current = getattr(current, bit)
              ^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NinjaJWTUserDefinedSettingsMapper' object has no attribute 'JSON_ENCODER'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/webhosting/mabb/env/lib/python3.11/site-packages/django/template/base.py", line 896, in _resolve_lookup
    current = current[int(bit)]
                      ^^^^^^^^
ValueError: invalid literal for int() with base 10: 'JSON_ENCODER'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/webhosting/mabb/env/lib/python3.11/site-packages/django/template/base.py", line 903, in _resolve_lookup
    raise VariableDoesNotExist(
django.template.base.VariableDoesNotExist: Failed lookup for key [JSON_ENCODER] in <ninja_jwt.settings.NinjaJWTUserDefinedSettingsMapper object at 0x7f3f39f94ad0>
Exception while resolving variable 'JSON_ENCODER' in template 'unknown'.
Traceback (most recent call last):
  File "/home/webhosting/mabb/env/lib/python3.11/site-packages/ninja/schema.py", line 54, in __getitem__
    item = getattr(self._obj, key)
           ^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NinjaJWTUserDefinedSettingsMapper' object has no attribute 'JSON_ENCODER'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/webhosting/mabb/env/lib/python3.11/site-packages/django/template/base.py", line 880, in _resolve_lookup
    current = current[bit]
              ~~~~~~~^^^^^
TypeError: 'NinjaJWTUserDefinedSettingsMapper' object is not subscriptable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/webhosting/mabb/env/lib/python3.11/site-packages/django/template/base.py", line 890, in _resolve_lookup
    current = getattr(current, bit)
              ^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NinjaJWTUserDefinedSettingsMapper' object has no attribute 'JSON_ENCODER'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/webhosting/mabb/env/lib/python3.11/site-packages/django/template/base.py", line 896, in _resolve_lookup
    current = current[int(bit)]
                      ^^^^^^^^
ValueError: invalid literal for int() with base 10: 'JSON_ENCODER'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/webhosting/mabb/env/lib/python3.11/site-packages/django/template/base.py", line 903, in _resolve_lookup
    raise VariableDoesNotExist(
django.template.base.VariableDoesNotExist: Failed lookup for key [JSON_ENCODER] in <ninja_jwt.settings.NinjaJWTUserDefinedSettingsMapper object at 0x7f3f39f950d0>
Exception while resolving variable 'JSON_ENCODER' in template 'unknown'.
Traceback (most recent call last):
  File "/home/webhosting/mabb/env/lib/python3.11/site-packages/ninja/schema.py", line 54, in __getitem__
    item = getattr(self._obj, key)
           ^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NinjaJWTUserDefinedSettingsMapper' object has no attribute 'JSON_ENCODER'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/webhosting/mabb/env/lib/python3.11/site-packages/django/template/base.py", line 880, in _resolve_lookup
    current = current[bit]
              ~~~~~~~^^^^^
TypeError: 'NinjaJWTUserDefinedSettingsMapper' object is not subscriptable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/webhosting/mabb/env/lib/python3.11/site-packages/django/template/base.py", line 890, in _resolve_lookup
    current = getattr(current, bit)
              ^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NinjaJWTUserDefinedSettingsMapper' object has no attribute 'JSON_ENCODER'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/webhosting/mabb/env/lib/python3.11/site-packages/django/template/base.py", line 896, in _resolve_lookup
    current = current[int(bit)]
                      ^^^^^^^^
ValueError: invalid literal for int() with base 10: 'JSON_ENCODER'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/webhosting/mabb/env/lib/python3.11/site-packages/django/template/base.py", line 903, in _resolve_lookup
    raise VariableDoesNotExist(
django.template.base.VariableDoesNotExist: Failed lookup for key [JSON_ENCODER] in <ninja_jwt.settings.NinjaJWTUserDefinedSettingsMapper object at 0x7f3f39f950d0>
Exception while resolving variable 'JSON_ENCODER' in template 'unknown'.
Traceback (most recent call last):
  File "/home/webhosting/mabb/env/lib/python3.11/site-packages/ninja/schema.py", line 54, in __getitem__
    item = getattr(self._obj, key)
           ^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NinjaJWTUserDefinedSettingsMapper' object has no attribute 'JSON_ENCODER'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/webhosting/mabb/env/lib/python3.11/site-packages/django/template/base.py", line 880, in _resolve_lookup
    current = current[bit]
              ~~~~~~~^^^^^
TypeError: 'NinjaJWTUserDefinedSettingsMapper' object is not subscriptable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/webhosting/mabb/env/lib/python3.11/site-packages/django/template/base.py", line 890, in _resolve_lookup
    current = getattr(current, bit)
              ^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NinjaJWTUserDefinedSettingsMapper' object has no attribute 'JSON_ENCODER'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/webhosting/mabb/env/lib/python3.11/site-packages/django/template/base.py", line 896, in _resolve_lookup
    current = current[int(bit)]
                      ^^^^^^^^
ValueError: invalid literal for int() with base 10: 'JSON_ENCODER'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/webhosting/mabb/env/lib/python3.11/site-packages/django/template/base.py", line 903, in _resolve_lookup
    raise VariableDoesNotExist(
django.template.base.VariableDoesNotExist: Failed lookup for key [JSON_ENCODER] in <ninja_jwt.settings.NinjaJWTUserDefinedSettingsMapper object at 0x7f3f39f90250>
Exception while resolving variable 'JSON_ENCODER' in template 'unknown'.
Traceback (most recent call last):
  File "/home/webhosting/mabb/env/lib/python3.11/site-packages/ninja/schema.py", line 54, in __getitem__
    item = getattr(self._obj, key)
           ^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NinjaJWTUserDefinedSettingsMapper' object has no attribute 'JSON_ENCODER'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/webhosting/mabb/env/lib/python3.11/site-packages/django/template/base.py", line 880, in _resolve_lookup
    current = current[bit]
              ~~~~~~~^^^^^
TypeError: 'NinjaJWTUserDefinedSettingsMapper' object is not subscriptable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/webhosting/mabb/env/lib/python3.11/site-packages/django/template/base.py", line 890, in _resolve_lookup
    current = getattr(current, bit)
              ^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NinjaJWTUserDefinedSettingsMapper' object has no attribute 'JSON_ENCODER'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/webhosting/mabb/env/lib/python3.11/site-packages/django/template/base.py", line 896, in _resolve_lookup
    current = current[int(bit)]
                      ^^^^^^^^
ValueError: invalid literal for int() with base 10: 'JSON_ENCODER'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/webhosting/mabb/env/lib/python3.11/site-packages/django/template/base.py", line 903, in _resolve_lookup
    raise VariableDoesNotExist(
django.template.base.VariableDoesNotExist: Failed lookup for key [JSON_ENCODER] in <ninja_jwt.settings.NinjaJWTUserDefinedSettingsMapper object at 0x7f3f39f90250>
Exception while resolving variable 'JSON_ENCODER' in template 'unknown'.
Traceback (most recent call last):
  File "/home/webhosting/mabb/env/lib/python3.11/site-packages/ninja/schema.py", line 54, in __getitem__
    item = getattr(self._obj, key)
           ^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NinjaJWTUserDefinedSettingsMapper' object has no attribute 'JSON_ENCODER'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/webhosting/mabb/env/lib/python3.11/site-packages/django/template/base.py", line 880, in _resolve_lookup
    current = current[bit]
              ~~~~~~~^^^^^
TypeError: 'NinjaJWTUserDefinedSettingsMapper' object is not subscriptable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/webhosting/mabb/env/lib/python3.11/site-packages/django/template/base.py", line 890, in _resolve_lookup
    current = getattr(current, bit)
              ^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NinjaJWTUserDefinedSettingsMapper' object has no attribute 'JSON_ENCODER'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/webhosting/mabb/env/lib/python3.11/site-packages/django/template/base.py", line 896, in _resolve_lookup
    current = current[int(bit)]
                      ^^^^^^^^
ValueError: invalid literal for int() with base 10: 'JSON_ENCODER'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/webhosting/mabb/env/lib/python3.11/site-packages/django/template/base.py", line 903, in _resolve_lookup
    raise VariableDoesNotExist(
django.template.base.VariableDoesNotExist: Failed lookup for key [JSON_ENCODER] in <ninja_jwt.settings.NinjaJWTUserDefinedSettingsMapper object at 0x7f3f39f90250>
Exception while resolving variable 'JSON_ENCODER' in template 'unknown'.
Traceback (most recent call last):
  File "/home/webhosting/mabb/env/lib/python3.11/site-packages/ninja/schema.py", line 54, in __getitem__
    item = getattr(self._obj, key)
           ^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NinjaJWTUserDefinedSettingsMapper' object has no attribute 'JSON_ENCODER'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/webhosting/mabb/env/lib/python3.11/site-packages/django/template/base.py", line 880, in _resolve_lookup
    current = current[bit]
              ~~~~~~~^^^^^
TypeError: 'NinjaJWTUserDefinedSettingsMapper' object is not subscriptable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/webhosting/mabb/env/lib/python3.11/site-packages/django/template/base.py", line 890, in _resolve_lookup
    current = getattr(current, bit)
              ^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NinjaJWTUserDefinedSettingsMapper' object has no attribute 'JSON_ENCODER'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/webhosting/mabb/env/lib/python3.11/site-packages/django/template/base.py", line 896, in _resolve_lookup
    current = current[int(bit)]
                      ^^^^^^^^
ValueError: invalid literal for int() with base 10: 'JSON_ENCODER'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/webhosting/mabb/env/lib/python3.11/site-packages/django/template/base.py", line 903, in _resolve_lookup
    raise VariableDoesNotExist(
django.template.base.VariableDoesNotExist: Failed lookup for key [JSON_ENCODER] in <ninja_jwt.settings.NinjaJWTUserDefinedSettingsMapper object at 0x7f3f39f90250>

@eadwinCode
Copy link
Owner

I will look into this... Can you also share your settings for NINJA_JWT ?

@jankrnavek
Copy link
Author

jankrnavek commented Jun 9, 2023

NINJA_JWT = {
    "ACCESS_TOKEN_LIFETIME": timedelta(minutes=120),
    "REFRESH_TOKEN_LIFETIME": timedelta(days=1),
    "ROTATE_REFRESH_TOKENS": False,
    "BLACKLIST_AFTER_ROTATION": False,
    "UPDATE_LAST_LOGIN": False,
    "ALGORITHM": "HS256",
    "SIGNING_KEY": SECRET_KEY,
    "VERIFYING_KEY": None,
    "AUDIENCE": None,
    "ISSUER": None,
    "JWK_URL": None,
    "LEEWAY": 0,
    "USER_ID_FIELD": "id",
    "USER_ID_CLAIM": "user_id",
    "USER_AUTHENTICATION_RULE": "ninja_jwt.authentication.default_user_authentication_rule",
    "AUTH_TOKEN_CLASSES": ("ninja_jwt.tokens.AccessToken",),
    "TOKEN_TYPE_CLAIM": "token_type",
    "TOKEN_USER_CLASS": "ninja_jwt.models.TokenUser",
    "JTI_CLAIM": "jti",
    "SLIDING_TOKEN_REFRESH_EXP_CLAIM": "refresh_exp",
    "SLIDING_TOKEN_LIFETIME": timedelta(minutes=5),
    "SLIDING_TOKEN_REFRESH_LIFETIME": timedelta(days=1),
    # For Controller Schemas
    # FOR OBTAIN PAIR
    "TOKEN_OBTAIN_PAIR_INPUT_SCHEMA": "ninja_jwt.schema.TokenObtainPairInputSchema",
    "TOKEN_OBTAIN_PAIR_REFRESH_INPUT_SCHEMA": "ninja_jwt.schema.TokenRefreshInputSchema",
    # FOR SLIDING TOKEN
    "TOKEN_OBTAIN_SLIDING_INPUT_SCHEMA": "ninja_jwt.schema.TokenObtainSlidingInputSchema",
    "TOKEN_OBTAIN_SLIDING_REFRESH_INPUT_SCHEMA": "ninja_jwt.schema.TokenRefreshSlidingInputSchema",
    "TOKEN_BLACKLIST_INPUT_SCHEMA": "ninja_jwt.schema.TokenBlacklistInputSchema",
    "TOKEN_VERIFY_INPUT_SCHEMA": "ninja_jwt.schema.TokenVerifyInputSchema",
}

And my controller looks like:

@api_controller("/users", auth=JWTAuth(), permissions=[IsAuthenticated])
class UsersController:
     pass

@eadwinCode
Copy link
Owner

@jankrnavek Whats your pydantic version?

@jankrnavek
Copy link
Author

C:\git\mabb> poetry show pydantic

 name         : pydantic                                                        
 version      : 1.10.9
 description  : Data validation and settings management using python type hints

dependencies
 - email-validator >=1.0.3
 - typing-extensions >=4.2.0

required by
 - django-ninja >=1.6,<2.0.0
 - ninja-schema *

@eadwinCode
Copy link
Owner

@jankrnavek I have tried to reproduce this error but its seems like its something specific to your project. Also I am a bit confused as to why a template VariableDoesNotExist exception is related to ninja_jwt settings.
NinjaJWTUserDefinedSettingsMapper is used in loading ninja_jwt settings with pydantic yet I don't see any errors from pydantic.

@eadwinCode
Copy link
Owner

Can you check in your project to see if your are using USER_SETTINGS from ninja_jwt anywhere? I am guessing your project is interacting with ninja_jwt USER_SETTINGS variable which is a NinjaJWTUserDefinedSettingsMapper object

@jankrnavek
Copy link
Author

I am not aware of using explicitly USER_SETTINGS anywhere in my code.
I am using own user model. Can that be a source of issue?

class User(AbstractUser):
    uid = models.UUIDField(default=uuid4, editable=False, unique=True, db_index=True)

    USERNAME_FIELD = "username"
    REQUIRED_FIELDS = ["email"]

    def __str__(self) -> str:
        return f"{self.username} ({self.email})"

    class Meta:
        verbose_name = _("user")
        verbose_name_plural = _("users")
        ordering = ["-pk"]

@eadwinCode
Copy link
Owner

No thats not the problem.

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