mirror of
https://github.com/django/django.git
synced 2025-01-18 14:24:39 +00:00
Refs #35090 -- Removed support for django.urls.register_converter() overriding existing converters per deprecation timeline.
This commit is contained in:
parent
1e331911a8
commit
9cb1ffa67b
@ -1,8 +1,5 @@
|
|||||||
import functools
|
import functools
|
||||||
import uuid
|
import uuid
|
||||||
import warnings
|
|
||||||
|
|
||||||
from django.utils.deprecation import RemovedInDjango60Warning
|
|
||||||
|
|
||||||
|
|
||||||
class IntConverter:
|
class IntConverter:
|
||||||
@ -57,14 +54,7 @@ REGISTERED_CONVERTERS = {}
|
|||||||
|
|
||||||
def register_converter(converter, type_name):
|
def register_converter(converter, type_name):
|
||||||
if type_name in REGISTERED_CONVERTERS or type_name in DEFAULT_CONVERTERS:
|
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!r} is already registered.")
|
||||||
# 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,
|
|
||||||
)
|
|
||||||
REGISTERED_CONVERTERS[type_name] = converter()
|
REGISTERED_CONVERTERS[type_name] = converter()
|
||||||
get_converters.cache_clear()
|
get_converters.cache_clear()
|
||||||
|
|
||||||
|
@ -150,10 +150,6 @@ The ``converter`` argument is a converter class, and ``type_name`` is the
|
|||||||
converter name to use in path patterns. See
|
converter name to use in path patterns. See
|
||||||
:ref:`registering-custom-path-converters` for an example.
|
:ref:`registering-custom-path-converters` for an example.
|
||||||
|
|
||||||
.. deprecated:: 5.1
|
|
||||||
|
|
||||||
Overriding existing converters is deprecated.
|
|
||||||
|
|
||||||
==================================================
|
==================================================
|
||||||
``django.conf.urls`` functions for use in URLconfs
|
``django.conf.urls`` functions for use in URLconfs
|
||||||
==================================================
|
==================================================
|
||||||
|
@ -271,4 +271,5 @@ to remove usage of these features.
|
|||||||
See :ref:`deprecated-features-5.1` for details on these changes, including how
|
See :ref:`deprecated-features-5.1` for details on these changes, including how
|
||||||
to remove usage of these features.
|
to remove usage of these features.
|
||||||
|
|
||||||
* ...
|
* ``django.urls.register_converter()`` no longer allows overriding existing
|
||||||
|
converters.
|
||||||
|
@ -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
|
Using regular expressions
|
||||||
=========================
|
=========================
|
||||||
|
|
||||||
|
@ -13,8 +13,7 @@ from django.urls import (
|
|||||||
resolve,
|
resolve,
|
||||||
reverse,
|
reverse,
|
||||||
)
|
)
|
||||||
from django.urls.converters import REGISTERED_CONVERTERS, IntConverter
|
from django.urls.converters import IntConverter
|
||||||
from django.utils.deprecation import RemovedInDjango60Warning
|
|
||||||
from django.views import View
|
from django.views import View
|
||||||
|
|
||||||
from .converters import Base64Converter, DynamicConverter
|
from .converters import Base64Converter, DynamicConverter
|
||||||
@ -204,35 +203,14 @@ class SimplifiedURLTests(SimpleTestCase):
|
|||||||
path("foo/<nonexistent:var>/", empty_view)
|
path("foo/<nonexistent:var>/", empty_view)
|
||||||
|
|
||||||
def test_warning_override_default_converter(self):
|
def test_warning_override_default_converter(self):
|
||||||
# RemovedInDjango60Warning: when the deprecation ends, replace with
|
msg = "Converter 'int' is already registered."
|
||||||
# msg = "Converter 'int' is already registered."
|
with self.assertRaisesMessage(ValueError, msg):
|
||||||
# with self.assertRaisesMessage(ValueError, msg):
|
register_converter(IntConverter, "int")
|
||||||
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__)
|
|
||||||
|
|
||||||
def test_warning_override_converter(self):
|
def test_warning_override_converter(self):
|
||||||
# RemovedInDjango60Warning: when the deprecation ends, replace with
|
msg = "Converter 'base64' is already registered."
|
||||||
# msg = "Converter 'base64' is already registered."
|
with self.assertRaisesMessage(ValueError, msg):
|
||||||
# with self.assertRaisesMessage(ValueError, msg):
|
register_converter(Base64Converter, "base64")
|
||||||
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__)
|
|
||||||
|
|
||||||
def test_invalid_view(self):
|
def test_invalid_view(self):
|
||||||
msg = "view must be a callable or a list/tuple in the case of include()."
|
msg = "view must be a callable or a list/tuple in the case of include()."
|
||||||
|
Loading…
x
Reference in New Issue
Block a user