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

[BUG] Converter uuid is already registered - deprecated in django 6.0 #1266

Open
mathiasertl opened this issue Aug 18, 2024 · 1 comment
Open

Comments

@mathiasertl
Copy link

Describe the bug

When running python -Wd ca/manage.py check I get a deprecation warning (paths trimmed for privacy):

user@host:~/src/...$ python -Wd ca/manage.py check
.../lib/python3.12/site-packages/ninja/signature/utils.py:96: RemovedInDjango60Warning: Converter 'uuid' is already registered. Support for overriding registered converters is deprecated and will be removed in Django 6.0.
  register_converter(NinjaUUIDConverter, "uuid")

django-ninja registers a converter called uuid, which is already registered by Django. Support for overriding a converter will be removed in Django 6.0. This converter is also problematic as it alters the behavior of views unrelated to django-ninja: A standard Django view using the uuid converter will receive a different type of value depending on if django-ninja is used or not - this was also already raised in #280.

From the looks of it, I think the converter can be safely removed. If not, it has to be renamed. Please advice on your preferred course of action, I'm happy to make a PR.

Versions (please complete the following information):

  • Python version: 3.12 (should not matter)
  • Django version: 5.1
  • Django-Ninja version: 1.3.0
  • Pydantic version: 2.8.2 (should not matter)
@Xdynix
Copy link

Xdynix commented Sep 8, 2024

Sharing a monkeypatch I used to suppress this behavior. The behavior of the uuid converter has always been to return a UUID instance since Django 2.0. I don't really think it should behave differently in Django Ninja than the int converter (i.e. returning str instead of the actual type).

Add the following code to your settings.py.

def monkeypatch_ninja_uuid_converter() -> None:
    import importlib
    import sys

    import django.urls

    module_name = "ninja.signature.utils"
    sys.modules.pop(module_name, None)

    original_register_converter = django.urls.register_converter

    def fake_register_converter(*_: Any, **__: Any) -> None:
        pass

    django.urls.register_converter = fake_register_converter
    importlib.import_module(module_name)

    django.urls.register_converter = original_register_converter


monkeypatch_ninja_uuid_converter()

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