Skip to content

Commit

Permalink
Fixed #31534 -- Deprecated django.conf.urls.url().
Browse files Browse the repository at this point in the history
  • Loading branch information
smithdc1 authored and felixxm committed May 5, 2020
1 parent f2051eb commit 2522559
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 11 deletions.
8 changes: 8 additions & 0 deletions django/conf/urls/__init__.py
@@ -1,4 +1,7 @@
import warnings

from django.urls import include, re_path
from django.utils.deprecation import RemovedInDjango40Warning
from django.views import defaults

__all__ = ['handler400', 'handler403', 'handler404', 'handler500', 'include', 'url']
Expand All @@ -10,4 +13,9 @@


def url(regex, view, kwargs=None, name=None):
warnings.warn(
'django.conf.urls.url() is deprecated in favor of '
'django.urls.re_path().',
RemovedInDjango40Warning,
)
return re_path(regex, view, kwargs, name)
4 changes: 2 additions & 2 deletions django/views/i18n.py
Expand Up @@ -196,8 +196,8 @@ class JavaScriptCatalog(View):
Return the selected language catalog as a JavaScript library.
Receive the list of packages to check for translations in the `packages`
kwarg either from the extra dictionary passed to the url() function or as a
plus-sign delimited string from the request. Default is 'django.conf'.
kwarg either from the extra dictionary passed to the path() function or as
a plus-sign delimited string from the request. Default is 'django.conf'.
You can override the gettext domain for this view, but usually you don't
want to do that as JavaScript messages go to the djangojs domain. This
Expand Down
2 changes: 2 additions & 0 deletions docs/internals/deprecation.txt
Expand Up @@ -81,6 +81,8 @@ details on these changes.
* The model ``NullBooleanField`` will be removed. A stub field will remain for
compatibility with historical migrations.

* ``django.conf.urls.url()`` will be removed.

See the :ref:`Django 3.1 release notes <deprecated-features-3.1>` for more
details on these changes.

Expand Down
7 changes: 5 additions & 2 deletions docs/ref/urls.txt
Expand Up @@ -141,8 +141,11 @@ Helper function to return a URL pattern for serving files in debug mode::

.. function:: url(regex, view, kwargs=None, name=None)

This function is an alias to :func:`django.urls.re_path()`. It's likely to be
deprecated in a future release.
This function is an alias to :func:`django.urls.re_path()`.

.. deprecated:: 3.1

Alias of :func:`django.urls.re_path` for backwards compatibility.

``handler400``
==============
Expand Down
2 changes: 1 addition & 1 deletion docs/releases/1.6.txt
Expand Up @@ -916,7 +916,7 @@ Miscellaneous
* :ref:`Authentication views <built-in-auth-views>` are now reversed by name,
not their locations in ``django.contrib.auth.views``. If you are using the
views without a ``name``, you should update your ``urlpatterns`` to use
:meth:`~django.conf.urls.url` with the ``name`` parameter. For example::
``django.conf.urls.url()`` with the ``name`` parameter. For example::

(r'^reset/done/$', 'django.contrib.auth.views.password_reset_complete')

Expand Down
2 changes: 1 addition & 1 deletion docs/releases/1.8.1.txt
Expand Up @@ -48,7 +48,7 @@ Bugfixes

* Updated ``urlpatterns`` examples generated by :djadmin:`startproject` to
remove usage of referencing views by dotted path in
:func:`~django.conf.urls.url` which is deprecated in Django 1.8
``django.conf.urls.url()`` which is deprecated in Django 1.8
(:ticket:`24635`).

* Fixed queries where an expression was referenced in ``order_by()``, but wasn't
Expand Down
8 changes: 4 additions & 4 deletions docs/releases/1.8.txt
Expand Up @@ -1270,7 +1270,7 @@ Thus ``patterns()`` serves little purpose and is a burden when teaching new user
(answering the newbie's question "why do I need this empty string as the first
argument to ``patterns()``?"). For these reasons, we are deprecating it.
Updating your code is as simple as ensuring that ``urlpatterns`` is a list of
:func:`django.conf.urls.url` instances. For example::
``django.conf.urls.url()`` instances. For example::

from django.conf.urls import url
from myapp import views
Expand All @@ -1280,8 +1280,8 @@ Updating your code is as simple as ensuring that ``urlpatterns`` is a list of
url('^other/$', views.otherview),
]

Passing a string as ``view`` to :func:`~django.conf.urls.url`
-------------------------------------------------------------
Passing a string as ``view`` to ``django.conf.urls.url()``
----------------------------------------------------------

Related to the previous item, referencing views as strings in the ``url()``
function is deprecated. Pass the callable view as described in the previous
Expand Down Expand Up @@ -1319,7 +1319,7 @@ instead.

Related to the previous item, the ``prefix`` argument to
:func:`django.conf.urls.i18n.i18n_patterns` has been deprecated. Simply pass a
list of :func:`django.conf.urls.url` instances instead.
list of ``django.conf.urls.url()`` instances instead.

Using an incorrect count of unpacked values in the :ttag:`for` template tag
---------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion docs/releases/1.9.txt
Expand Up @@ -1289,7 +1289,7 @@ to:

This change also means that the old way of including an ``AdminSite`` instance
is deprecated. Instead, pass ``admin.site.urls`` directly to
:func:`~django.conf.urls.url()`:
``django.conf.urls.url()``:

.. code-block:: python
:caption: urls.py
Expand Down
3 changes: 3 additions & 0 deletions docs/releases/3.1.txt
Expand Up @@ -754,6 +754,9 @@ Miscellaneous
* The ``NullBooleanField`` model field is deprecated in favor of
``BooleanField(null=True)``.

* ``django.conf.urls.url()`` alias of :func:`django.urls.re_path` is
deprecated.

.. _removed-features-3.1:

Features removed in 3.1
Expand Down
12 changes: 12 additions & 0 deletions tests/urlpatterns/tests.py
@@ -1,9 +1,11 @@
import uuid

from django.conf.urls import url as conf_url
from django.core.exceptions import ImproperlyConfigured
from django.test import SimpleTestCase
from django.test.utils import override_settings
from django.urls import NoReverseMatch, Resolver404, path, resolve, reverse
from django.utils.deprecation import RemovedInDjango40Warning

from .converters import DynamicConverter
from .views import empty_view
Expand Down Expand Up @@ -303,3 +305,13 @@ def raises_type_error(value):
raise TypeError('This type error propagates.')
with self.assertRaisesMessage(TypeError, 'This type error propagates.'):
reverse('dynamic', kwargs={'value': object()})


class DeprecationTests(SimpleTestCase):
def test_url_warning(self):
msg = (
'django.conf.urls.url() is deprecated in favor of '
'django.urls.re_path().'
)
with self.assertRaisesMessage(RemovedInDjango40Warning, msg):
conf_url(r'^regex/(?P<pk>[0-9]+)/$', empty_view, name='regex')

0 comments on commit 2522559

Please sign in to comment.