1
0
mirror of https://github.com/django/django.git synced 2025-01-18 06:12:23 +00:00

Refs #35090 -- Removed support for django.urls.register_converter() overriding existing converters per deprecation timeline.

This commit is contained in:
Sarah Boyce 2024-12-12 17:11:22 +01:00
parent 1e331911a8
commit 9cb1ffa67b
5 changed files with 10 additions and 50 deletions

View File

@ -1,8 +1,5 @@
import functools
import uuid
import warnings
from django.utils.deprecation import RemovedInDjango60Warning
class IntConverter:
@ -57,14 +54,7 @@ REGISTERED_CONVERTERS = {}
def register_converter(converter, type_name):
if type_name in REGISTERED_CONVERTERS or type_name in DEFAULT_CONVERTERS:
# RemovedInDjango60Warning: when the deprecation ends, replace with
# raise ValueError(f"Converter {type_name} is already registered.")
warnings.warn(
f"Converter {type_name!r} is already registered. Support for overriding "
"registered converters is deprecated and will be removed in Django 6.0.",
RemovedInDjango60Warning,
stacklevel=2,
)
raise ValueError(f"Converter {type_name!r} is already registered.")
REGISTERED_CONVERTERS[type_name] = converter()
get_converters.cache_clear()

View File

@ -150,10 +150,6 @@ The ``converter`` argument is a converter class, and ``type_name`` is the
converter name to use in path patterns. See
:ref:`registering-custom-path-converters` for an example.
.. deprecated:: 5.1
Overriding existing converters is deprecated.
==================================================
``django.conf.urls`` functions for use in URLconfs
==================================================

View File

@ -271,4 +271,5 @@ to remove usage of these features.
See :ref:`deprecated-features-5.1` for details on these changes, including how
to remove usage of these features.
* ...
* ``django.urls.register_converter()`` no longer allows overriding existing
converters.

View File

@ -183,11 +183,6 @@ Register custom converter classes in your URLconf using
...,
]
.. deprecated:: 5.1
Overriding existing converters with ``django.urls.register_converter()`` is
deprecated.
Using regular expressions
=========================

View File

@ -13,8 +13,7 @@ from django.urls import (
resolve,
reverse,
)
from django.urls.converters import REGISTERED_CONVERTERS, IntConverter
from django.utils.deprecation import RemovedInDjango60Warning
from django.urls.converters import IntConverter
from django.views import View
from .converters import Base64Converter, DynamicConverter
@ -204,35 +203,14 @@ class SimplifiedURLTests(SimpleTestCase):
path("foo/<nonexistent:var>/", empty_view)
def test_warning_override_default_converter(self):
# RemovedInDjango60Warning: when the deprecation ends, replace with
# msg = "Converter 'int' is already registered."
# with self.assertRaisesMessage(ValueError, msg):
msg = (
"Converter 'int' is already registered. Support for overriding registered "
"converters is deprecated and will be removed in Django 6.0."
)
try:
with self.assertWarnsMessage(RemovedInDjango60Warning, msg) as ctx:
register_converter(IntConverter, "int")
finally:
REGISTERED_CONVERTERS.pop("int", None)
self.assertEqual(ctx.filename, __file__)
msg = "Converter 'int' is already registered."
with self.assertRaisesMessage(ValueError, msg):
register_converter(IntConverter, "int")
def test_warning_override_converter(self):
# RemovedInDjango60Warning: when the deprecation ends, replace with
# msg = "Converter 'base64' is already registered."
# with self.assertRaisesMessage(ValueError, msg):
msg = (
"Converter 'base64' is already registered. Support for overriding "
"registered converters is deprecated and will be removed in Django 6.0."
)
try:
with self.assertWarnsMessage(RemovedInDjango60Warning, msg) as ctx:
register_converter(Base64Converter, "base64")
register_converter(Base64Converter, "base64")
finally:
REGISTERED_CONVERTERS.pop("base64", None)
self.assertEqual(ctx.filename, __file__)
msg = "Converter 'base64' is already registered."
with self.assertRaisesMessage(ValueError, msg):
register_converter(Base64Converter, "base64")
def test_invalid_view(self):
msg = "view must be a callable or a list/tuple in the case of include()."