2021-01-05 18:07:46 +08:00
|
|
|
============================================
|
|
|
|
Django 4.0 release notes - UNDER DEVELOPMENT
|
|
|
|
============================================
|
|
|
|
|
|
|
|
*Expected December 2021*
|
|
|
|
|
|
|
|
Welcome to Django 4.0!
|
|
|
|
|
|
|
|
These release notes cover the :ref:`new features <whats-new-4.0>`, as well as
|
|
|
|
some :ref:`backwards incompatible changes <backwards-incompatible-4.0>` you'll
|
|
|
|
want to be aware of when upgrading from Django 3.2 or earlier. We've
|
|
|
|
:ref:`begun the deprecation process for some features
|
|
|
|
<deprecated-features-4.0>`.
|
|
|
|
|
|
|
|
See the :doc:`/howto/upgrade-version` guide if you're updating an existing
|
|
|
|
project.
|
|
|
|
|
|
|
|
Python compatibility
|
|
|
|
====================
|
|
|
|
|
|
|
|
Django 4.0 supports Python 3.8, 3.9, and 3.10. We **highly recommend** and only
|
|
|
|
officially support the latest release of each series.
|
|
|
|
|
2021-01-19 15:35:16 +08:00
|
|
|
The Django 3.2.x series is the last to support Python 3.6 and 3.7.
|
|
|
|
|
2021-01-05 18:07:46 +08:00
|
|
|
.. _whats-new-4.0:
|
|
|
|
|
|
|
|
What's new in Django 4.0
|
|
|
|
========================
|
|
|
|
|
2021-02-07 03:45:54 +08:00
|
|
|
Functional unique constraints
|
|
|
|
-----------------------------
|
|
|
|
|
|
|
|
The new :attr:`*expressions <django.db.models.UniqueConstraint.expressions>`
|
|
|
|
positional argument of
|
|
|
|
:class:`UniqueConstraint() <django.db.models.UniqueConstraint>` enables
|
|
|
|
creating functional unique constraints on expressions and database functions.
|
|
|
|
For example::
|
|
|
|
|
|
|
|
from django.db import models
|
|
|
|
from django.db.models import UniqueConstraint
|
|
|
|
from django.db.models.functions import Lower
|
|
|
|
|
|
|
|
|
|
|
|
class MyModel(models.Model):
|
|
|
|
first_name = models.CharField(max_length=255)
|
|
|
|
last_name = models.CharField(max_length=255)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
indexes = [
|
|
|
|
UniqueConstraint(
|
|
|
|
Lower('first_name'),
|
|
|
|
Lower('last_name').desc(),
|
|
|
|
name='first_last_name_unique',
|
|
|
|
),
|
|
|
|
]
|
|
|
|
|
|
|
|
Functional unique constraints are added to models using the
|
|
|
|
:attr:`Meta.constraints <django.db.models.Options.constraints>` option.
|
|
|
|
|
2021-01-05 18:07:46 +08:00
|
|
|
Minor features
|
|
|
|
--------------
|
|
|
|
|
|
|
|
:mod:`django.contrib.admin`
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2021-01-10 16:00:18 +08:00
|
|
|
* The ``admin/base.html`` template now has a new block ``header`` which
|
|
|
|
contains the admin site header.
|
2021-01-05 18:07:46 +08:00
|
|
|
|
2020-11-27 04:51:35 +08:00
|
|
|
* The new :meth:`.ModelAdmin.get_formset_kwargs` method allows customizing the
|
|
|
|
keyword arguments passed to the constructor of a formset.
|
|
|
|
|
2021-01-05 18:07:46 +08:00
|
|
|
:mod:`django.contrib.admindocs`
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2021-02-03 22:31:20 +08:00
|
|
|
* The admindocs now allows esoteric setups where :setting:`ROOT_URLCONF` is not
|
|
|
|
a string.
|
2021-01-05 18:07:46 +08:00
|
|
|
|
2021-02-10 20:33:57 +08:00
|
|
|
* The model section of the ``admindocs`` now shows cached properties.
|
|
|
|
|
2021-01-05 18:07:46 +08:00
|
|
|
:mod:`django.contrib.auth`
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2021-01-14 17:46:29 +08:00
|
|
|
* The default iteration count for the PBKDF2 password hasher is increased from
|
|
|
|
260,000 to 320,000.
|
2021-01-05 18:07:46 +08:00
|
|
|
|
2017-06-07 22:48:28 +08:00
|
|
|
* The new
|
|
|
|
:attr:`LoginView.next_page <django.contrib.auth.views.LoginView.next_page>`
|
|
|
|
attribute and
|
|
|
|
:meth:`~django.contrib.auth.views.LoginView.get_default_redirect_url` method
|
|
|
|
allow customizing the redirect after login.
|
|
|
|
|
2021-01-05 18:07:46 +08:00
|
|
|
:mod:`django.contrib.contenttypes`
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
* ...
|
|
|
|
|
|
|
|
:mod:`django.contrib.gis`
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
* ...
|
|
|
|
|
|
|
|
:mod:`django.contrib.messages`
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
* ...
|
|
|
|
|
|
|
|
:mod:`django.contrib.postgres`
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2020-12-24 06:39:43 +08:00
|
|
|
* The PostgreSQL backend now supports connecting by a service name. See
|
|
|
|
:ref:`postgresql-connection-settings` for more details.
|
2021-01-05 18:07:46 +08:00
|
|
|
|
|
|
|
:mod:`django.contrib.redirects`
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
* ...
|
|
|
|
|
|
|
|
:mod:`django.contrib.sessions`
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
* ...
|
|
|
|
|
|
|
|
:mod:`django.contrib.sitemaps`
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
* ...
|
|
|
|
|
|
|
|
:mod:`django.contrib.sites`
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
* ...
|
|
|
|
|
|
|
|
:mod:`django.contrib.staticfiles`
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
* ...
|
|
|
|
|
|
|
|
:mod:`django.contrib.syndication`
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
* ...
|
|
|
|
|
|
|
|
Cache
|
|
|
|
~~~~~
|
|
|
|
|
|
|
|
* ...
|
|
|
|
|
|
|
|
CSRF
|
|
|
|
~~~~
|
|
|
|
|
|
|
|
* ...
|
|
|
|
|
|
|
|
Decorators
|
|
|
|
~~~~~~~~~~
|
|
|
|
|
|
|
|
* ...
|
|
|
|
|
|
|
|
Email
|
|
|
|
~~~~~
|
|
|
|
|
|
|
|
* ...
|
|
|
|
|
|
|
|
Error Reporting
|
|
|
|
~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
* ...
|
|
|
|
|
|
|
|
File Storage
|
|
|
|
~~~~~~~~~~~~
|
|
|
|
|
|
|
|
* ...
|
|
|
|
|
|
|
|
File Uploads
|
|
|
|
~~~~~~~~~~~~
|
|
|
|
|
|
|
|
* ...
|
|
|
|
|
|
|
|
Forms
|
|
|
|
~~~~~
|
|
|
|
|
2021-01-26 14:35:20 +08:00
|
|
|
* :class:`~django.forms.ModelChoiceField` now includes the provided value in
|
|
|
|
the ``params`` argument of a raised
|
|
|
|
:exc:`~django.core.exceptions.ValidationError` for the ``invalid_choice``
|
|
|
|
error message. This allows custom error messages to use the ``%(value)s``
|
|
|
|
placeholder.
|
2021-01-05 18:07:46 +08:00
|
|
|
|
|
|
|
Generic Views
|
|
|
|
~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
* ...
|
|
|
|
|
|
|
|
Internationalization
|
|
|
|
~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
* ...
|
|
|
|
|
|
|
|
Logging
|
|
|
|
~~~~~~~
|
|
|
|
|
|
|
|
* ...
|
|
|
|
|
|
|
|
Management Commands
|
|
|
|
~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2020-12-24 23:29:54 +08:00
|
|
|
* The :djadmin:`runserver` management command now supports the
|
|
|
|
:option:`--skip-checks` option.
|
2021-01-05 18:07:46 +08:00
|
|
|
|
2021-02-25 00:16:45 +08:00
|
|
|
* On PostgreSQL, :djadmin:`dbshell` now supports specifying a password file.
|
|
|
|
|
2021-01-05 18:07:46 +08:00
|
|
|
Migrations
|
|
|
|
~~~~~~~~~~
|
|
|
|
|
|
|
|
* ...
|
|
|
|
|
|
|
|
Models
|
|
|
|
~~~~~~
|
|
|
|
|
2020-06-09 17:23:31 +08:00
|
|
|
* New :meth:`QuerySet.contains(obj) <.QuerySet.contains>` method returns
|
|
|
|
whether the queryset contains the given object. This tries to perform the
|
|
|
|
query in the simplest and fastest way possible.
|
2021-01-05 18:07:46 +08:00
|
|
|
|
|
|
|
Requests and Responses
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
* ...
|
|
|
|
|
|
|
|
Security
|
|
|
|
~~~~~~~~
|
|
|
|
|
|
|
|
* ...
|
|
|
|
|
|
|
|
Serialization
|
|
|
|
~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
* ...
|
|
|
|
|
|
|
|
Signals
|
|
|
|
~~~~~~~
|
|
|
|
|
2021-01-29 23:19:06 +08:00
|
|
|
* The new ``stdout`` argument for :func:`~django.db.models.signals.pre_migrate`
|
|
|
|
and :func:`~django.db.models.signals.post_migrate` signals allows redirecting
|
|
|
|
output to a stream-like object. It should be preferred over
|
|
|
|
:py:data:`sys.stdout` and :py:func:`print` when emitting verbose output in
|
|
|
|
order to allow proper capture when testing.
|
2021-01-05 18:07:46 +08:00
|
|
|
|
|
|
|
Templates
|
|
|
|
~~~~~~~~~
|
|
|
|
|
|
|
|
* ...
|
|
|
|
|
|
|
|
Tests
|
|
|
|
~~~~~
|
|
|
|
|
2021-02-15 11:42:47 +08:00
|
|
|
* The new ``serialized_aliases`` argument of
|
|
|
|
:func:`django.test.utils.setup_databases` determines which
|
|
|
|
:setting:`DATABASES` aliases test databases should have their state
|
|
|
|
serialized to allow usage of the
|
|
|
|
:ref:`serialized_rollback <test-case-serialized-rollback>` feature.
|
2021-01-05 18:07:46 +08:00
|
|
|
|
|
|
|
URLs
|
|
|
|
~~~~
|
|
|
|
|
|
|
|
* ...
|
|
|
|
|
|
|
|
Utilities
|
|
|
|
~~~~~~~~~
|
|
|
|
|
|
|
|
* ...
|
|
|
|
|
|
|
|
Validators
|
|
|
|
~~~~~~~~~~
|
|
|
|
|
|
|
|
* ...
|
|
|
|
|
|
|
|
.. _backwards-incompatible-4.0:
|
|
|
|
|
|
|
|
Backwards incompatible changes in 4.0
|
|
|
|
=====================================
|
|
|
|
|
|
|
|
Database backend API
|
|
|
|
--------------------
|
|
|
|
|
|
|
|
This section describes changes that may be needed in third-party database
|
|
|
|
backends.
|
|
|
|
|
|
|
|
* ...
|
|
|
|
|
2021-01-19 19:25:20 +08:00
|
|
|
:mod:`django.contrib.gis`
|
|
|
|
-------------------------
|
|
|
|
|
|
|
|
* Support for PostGIS 2.3 is removed.
|
|
|
|
|
|
|
|
Dropped support for PostgreSQL 9.6
|
|
|
|
----------------------------------
|
|
|
|
|
|
|
|
Upstream support for PostgreSQL 9.6 ends in November 2021. Django 4.0 supports
|
|
|
|
PostgreSQL 10 and higher.
|
|
|
|
|
2021-01-29 14:03:40 +08:00
|
|
|
Dropped support for Oracle 12.2 and 18c
|
|
|
|
---------------------------------------
|
|
|
|
|
|
|
|
Upstream support for Oracle 12.2 ends in March 2022 and for Oracle 18c it ends
|
|
|
|
in June 2021. Django 3.2 will be supported until April 2024. Django 4.0
|
|
|
|
officially supports Oracle 19c.
|
|
|
|
|
2021-01-05 18:07:46 +08:00
|
|
|
Miscellaneous
|
|
|
|
-------------
|
|
|
|
|
2021-01-29 20:07:05 +08:00
|
|
|
* Support for ``cx_Oracle`` < 7.0 is removed.
|
2021-01-05 18:07:46 +08:00
|
|
|
|
2021-02-14 03:07:55 +08:00
|
|
|
* To allow serving a Django site on a subpath without changing the value of
|
|
|
|
:setting:`STATIC_URL`, the leading slash is removed from that setting (now
|
|
|
|
``'static/'``) in the default :djadmin:`startproject` template.
|
2021-01-29 22:14:21 +08:00
|
|
|
|
2021-03-03 16:13:07 +08:00
|
|
|
* The :class:`~django.contrib.admin.AdminSite` method for the admin ``index``
|
|
|
|
view is no longer decorated with ``never_cache`` when accessed directly,
|
|
|
|
rather than via the recommended ``AdminSite.urls`` property, or
|
|
|
|
``AdminSite.get_urls()`` method.
|
|
|
|
|
2021-03-10 16:16:28 +08:00
|
|
|
* Unsupported operations on a sliced queryset now raise ``TypeError`` instead
|
|
|
|
of ``AssertionError``.
|
|
|
|
|
2021-03-09 00:29:44 +08:00
|
|
|
* The undocumented ``django.test.runner.reorder_suite()`` function is renamed
|
|
|
|
to ``reorder_tests()``. It now accepts an iterable of tests rather than a
|
|
|
|
test suite, and returns an iterator of tests.
|
|
|
|
|
2021-01-05 18:07:46 +08:00
|
|
|
.. _deprecated-features-4.0:
|
|
|
|
|
|
|
|
Features deprecated in 4.0
|
|
|
|
==========================
|
|
|
|
|
|
|
|
Miscellaneous
|
|
|
|
-------------
|
|
|
|
|
2021-02-15 11:42:47 +08:00
|
|
|
* ``SERIALIZE`` test setting is deprecated as it can be inferred from the
|
|
|
|
:attr:`~django.test.TestCase.databases` with the
|
|
|
|
:ref:`serialized_rollback <test-case-serialized-rollback>` option enabled.
|
2021-01-05 18:07:46 +08:00
|
|
|
|
|
|
|
Features removed in 4.0
|
|
|
|
=======================
|
|
|
|
|
|
|
|
These features have reached the end of their deprecation cycle and are removed
|
|
|
|
in Django 4.0.
|
|
|
|
|
|
|
|
See :ref:`deprecated-features-3.0` for details on these changes, including how
|
|
|
|
to remove usage of these features.
|
|
|
|
|
2021-01-05 19:18:04 +08:00
|
|
|
* ``django.utils.http.urlquote()``, ``urlquote_plus()``, ``urlunquote()``, and
|
|
|
|
``urlunquote_plus()`` are removed.
|
2021-01-05 18:07:46 +08:00
|
|
|
|
2021-01-05 19:27:52 +08:00
|
|
|
* ``django.utils.encoding.force_text()`` and ``smart_text()`` are removed.
|
|
|
|
|
2021-01-05 19:45:08 +08:00
|
|
|
* ``django.utils.translation.ugettext()``, ``ugettext_lazy()``,
|
|
|
|
``ugettext_noop()``, ``ungettext()``, and ``ungettext_lazy()`` are removed.
|
|
|
|
|
2021-01-06 20:16:24 +08:00
|
|
|
* ``django.views.i18n.set_language()`` doesn't set the user language in
|
|
|
|
``request.session`` (key ``_language``).
|
|
|
|
|
2021-01-07 14:55:06 +08:00
|
|
|
* ``alias=None`` is required in the signature of
|
|
|
|
``django.db.models.Expression.get_group_by_cols()`` subclasses.
|
|
|
|
|
2021-01-07 15:09:04 +08:00
|
|
|
* ``django.utils.text.unescape_entities()`` is removed.
|
|
|
|
|
2021-01-07 15:15:39 +08:00
|
|
|
* ``django.utils.http.is_safe_url()`` is removed.
|
|
|
|
|
2021-01-05 18:07:46 +08:00
|
|
|
See :ref:`deprecated-features-3.1` for details on these changes, including how
|
|
|
|
to remove usage of these features.
|
|
|
|
|
2021-01-07 20:10:37 +08:00
|
|
|
* The ``PASSWORD_RESET_TIMEOUT_DAYS`` setting is removed.
|
2021-01-08 03:50:36 +08:00
|
|
|
|
|
|
|
* The :lookup:`isnull` lookup no longer allows using non-boolean values as the
|
|
|
|
right-hand side.
|
2021-01-08 03:56:49 +08:00
|
|
|
|
|
|
|
* The ``django.db.models.query_utils.InvalidQuery`` exception class is removed.
|
2021-01-10 03:31:27 +08:00
|
|
|
|
|
|
|
* The ``django-admin.py`` entry point is removed.
|
2021-01-11 19:27:40 +08:00
|
|
|
|
|
|
|
* The ``HttpRequest.is_ajax()`` method is removed.
|
2021-01-11 19:49:16 +08:00
|
|
|
|
|
|
|
* Support for the pre-Django 3.1 encoding format of cookies values used by
|
|
|
|
``django.contrib.messages.storage.cookie.CookieStorage`` is removed.
|
2021-01-12 03:31:49 +08:00
|
|
|
|
|
|
|
* Support for the pre-Django 3.1 password reset tokens in the admin site (that
|
|
|
|
use the SHA-1 hashing algorithm) is removed.
|
2021-01-12 04:27:01 +08:00
|
|
|
|
|
|
|
* Support for the pre-Django 3.1 encoding format of sessions is removed.
|
2021-01-12 04:57:48 +08:00
|
|
|
|
|
|
|
* Support for the pre-Django 3.1 ``django.core.signing.Signer`` signatures
|
|
|
|
(encoded with the SHA-1 algorithm) is removed.
|
|
|
|
|
|
|
|
* Support for the pre-Django 3.1 ``django.core.signing.dumps()`` signatures
|
|
|
|
(encoded with the SHA-1 algorithm) in ``django.core.signing.loads()`` is
|
|
|
|
removed.
|
2021-01-13 03:31:36 +08:00
|
|
|
|
|
|
|
* Support for the pre-Django 3.1 user sessions (that use the SHA-1 algorithm)
|
|
|
|
is removed.
|
2021-01-13 03:55:32 +08:00
|
|
|
|
|
|
|
* The ``get_request`` argument for
|
|
|
|
``django.utils.deprecation.MiddlewareMixin.__init__()`` is required and
|
|
|
|
doesn't accept ``None``.
|
2021-01-13 18:08:32 +08:00
|
|
|
|
|
|
|
* The ``providing_args`` argument for ``django.dispatch.Signal`` is removed.
|
2021-01-13 19:29:58 +08:00
|
|
|
|
2021-01-14 05:33:42 +08:00
|
|
|
* The ``length`` argument for ``django.utils.crypto.get_random_string()`` is
|
|
|
|
required.
|
|
|
|
|
2021-01-13 19:29:58 +08:00
|
|
|
* The ``list`` message for ``ModelMultipleChoiceField`` is removed.
|
2021-01-13 19:52:13 +08:00
|
|
|
|
|
|
|
* Support for passing raw column aliases to ``QuerySet.order_by()`` is removed.
|
2021-01-14 04:28:09 +08:00
|
|
|
|
|
|
|
* The ``NullBooleanField`` model field is removed, except for support in
|
|
|
|
historical migrations.
|
2021-01-14 16:06:39 +08:00
|
|
|
|
|
|
|
* ``django.conf.urls.url()`` is removed.
|
2021-01-14 16:33:12 +08:00
|
|
|
|
|
|
|
* The ``django.contrib.postgres.fields.JSONField`` model field is removed,
|
|
|
|
except for support in historical migrations.
|
2021-01-14 16:57:22 +08:00
|
|
|
|
|
|
|
* ``django.contrib.postgres.fields.jsonb.KeyTransform`` and
|
|
|
|
``django.contrib.postgres.fields.jsonb.KeyTextTransform`` are removed.
|
2021-01-14 17:04:20 +08:00
|
|
|
|
|
|
|
* ``django.contrib.postgres.forms.JSONField`` is removed.
|
2021-01-14 17:14:57 +08:00
|
|
|
|
|
|
|
* The ``{% ifequal %}`` and ``{% ifnotequal %}`` template tags are removed.
|
2021-01-14 17:27:04 +08:00
|
|
|
|
|
|
|
* The ``DEFAULT_HASHING_ALGORITHM`` transitional setting is removed.
|