| 1 |
======================== |
| 2 |
Django 5.0 release notes |
| 3 |
======================== |
| 4 |
|
| 5 |
*December 4, 2023* |
| 6 |
|
| 7 |
Welcome to Django 5.0! |
| 8 |
|
| 9 |
These release notes cover the :ref:`new features <whats-new-5.0>`, as well as |
| 10 |
some :ref:`backwards incompatible changes <backwards-incompatible-5.0>` you'll |
| 11 |
want to be aware of when upgrading from Django 4.2 or earlier. We've |
| 12 |
:ref:`begun the deprecation process for some features |
| 13 |
<deprecated-features-5.0>`. |
| 14 |
|
| 15 |
See the :doc:`/howto/upgrade-version` guide if you're updating an existing |
| 16 |
project. |
| 17 |
|
| 18 |
Python compatibility |
| 19 |
==================== |
| 20 |
|
| 21 |
Django 5.0 supports Python 3.10, 3.11, and 3.12. We **highly recommend** and |
| 22 |
only officially support the latest release of each series. |
| 23 |
|
| 24 |
The Django 4.2.x series is the last to support Python 3.8 and 3.9. |
| 25 |
|
| 26 |
Third-party library support for older version of Django |
| 27 |
======================================================= |
| 28 |
|
| 29 |
Following the release of Django 5.0, we suggest that third-party app authors |
| 30 |
drop support for all versions of Django prior to 4.2. At that time, you should |
| 31 |
be able to run your package's tests using ``python -Wd`` so that deprecation |
| 32 |
warnings appear. After making the deprecation warning fixes, your app should be |
| 33 |
compatible with Django 5.0. |
| 34 |
|
| 35 |
.. _whats-new-5.0: |
| 36 |
|
| 37 |
What's new in Django 5.0 |
| 38 |
======================== |
| 39 |
|
| 40 |
Facet filters in the admin |
| 41 |
-------------------------- |
| 42 |
|
| 43 |
Facet counts are now shown for applied filters in the admin changelist when |
| 44 |
toggled on via the UI. This behavior can be changed via the new |
| 45 |
:attr:`.ModelAdmin.show_facets` attribute. For more information see |
| 46 |
:ref:`facet-filters`. |
| 47 |
|
| 48 |
Simplified templates for form field rendering |
| 49 |
--------------------------------------------- |
| 50 |
|
| 51 |
Django 5.0 introduces the concept of a field group, and field group templates. |
| 52 |
This simplifies rendering of the related elements of a Django form field such |
| 53 |
as its label, widget, help text, and errors. |
| 54 |
|
| 55 |
For example, the template below: |
| 56 |
|
| 57 |
.. code-block:: html+django |
| 58 |
|
| 59 |
<form> |
| 60 |
... |
| 61 |
<div> |
| 62 |
{{ form.name.label_tag }} |
| 63 |
{% if form.name.help_text %} |
| 64 |
<div class="helptext" id="{{ form.name.auto_id }}_helptext"> |
| 65 |
{{ form.name.help_text|safe }} |
| 66 |
</div> |
| 67 |
{% endif %} |
| 68 |
{{ form.name.errors }} |
| 69 |
{{ form.name }} |
| 70 |
<div class="row"> |
| 71 |
<div class="col"> |
| 72 |
{{ form.email.label_tag }} |
| 73 |
{% if form.email.help_text %} |
| 74 |
<div class="helptext" id="{{ form.email.auto_id }}_helptext"> |
| 75 |
{{ form.email.help_text|safe }} |
| 76 |
</div> |
| 77 |
{% endif %} |
| 78 |
{{ form.email.errors }} |
| 79 |
{{ form.email }} |
| 80 |
</div> |
| 81 |
<div class="col"> |
| 82 |
{{ form.password.label_tag }} |
| 83 |
{% if form.password.help_text %} |
| 84 |
<div class="helptext" id="{{ form.password.auto_id }}_helptext"> |
| 85 |
{{ form.password.help_text|safe }} |
| 86 |
</div> |
| 87 |
{% endif %} |
| 88 |
{{ form.password.errors }} |
| 89 |
{{ form.password }} |
| 90 |
</div> |
| 91 |
</div> |
| 92 |
</div> |
| 93 |
... |
| 94 |
</form> |
| 95 |
|
| 96 |
Can now be simplified to: |
| 97 |
|
| 98 |
.. code-block:: html+django |
| 99 |
|
| 100 |
<form> |
| 101 |
... |
| 102 |
<div> |
| 103 |
{{ form.name.as_field_group }} |
| 104 |
<div class="row"> |
| 105 |
<div class="col">{{ form.email.as_field_group }}</div> |
| 106 |
<div class="col">{{ form.password.as_field_group }}</div> |
| 107 |
</div> |
| 108 |
</div> |
| 109 |
... |
| 110 |
</form> |
| 111 |
|
| 112 |
:meth:`~django.forms.BoundField.as_field_group` renders fields with the |
| 113 |
``"django/forms/field.html"`` template by default and can be customized on a |
| 114 |
per-project, per-field, or per-request basis. See |
| 115 |
:ref:`reusable-field-group-templates`. |
| 116 |
|
| 117 |
Database-computed default values |
| 118 |
-------------------------------- |
| 119 |
|
| 120 |
The new :attr:`Field.db_default <django.db.models.Field.db_default>` parameter |
| 121 |
sets a database-computed default value. For example:: |
| 122 |
|
| 123 |
from django.db import models |
| 124 |
from django.db.models.functions import Now, Pi |
| 125 |
|
| 126 |
|
| 127 |
class MyModel(models.Model): |
| 128 |
age = models.IntegerField(db_default=18) |
| 129 |
created = models.DateTimeField(db_default=Now()) |
| 130 |
circumference = models.FloatField(db_default=2 * Pi()) |
| 131 |
|
| 132 |
Database generated model field |
| 133 |
------------------------------ |
| 134 |
|
| 135 |
The new :class:`~django.db.models.GeneratedField` allows creation of database |
| 136 |
generated columns. This field can be used on all supported database backends |
| 137 |
to create a field that is always computed from other fields. For example:: |
| 138 |
|
| 139 |
from django.db import models |
| 140 |
from django.db.models import F |
| 141 |
|
| 142 |
|
| 143 |
class Square(models.Model): |
| 144 |
side = models.IntegerField() |
| 145 |
area = models.GeneratedField( |
| 146 |
expression=F("side") * F("side"), |
| 147 |
output_field=models.BigIntegerField(), |
| 148 |
db_persist=True, |
| 149 |
) |
| 150 |
|
| 151 |
More options for declaring field choices |
| 152 |
---------------------------------------- |
| 153 |
|
| 154 |
:attr:`.Field.choices` *(for model fields)* and :attr:`.ChoiceField.choices` |
| 155 |
*(for form fields)* allow for more flexibility when declaring their values. In |
| 156 |
previous versions of Django, ``choices`` should either be a list of 2-tuples, |
| 157 |
or an :ref:`field-choices-enum-types` subclass, but the latter required |
| 158 |
accessing the ``.choices`` attribute to provide the values in the expected |
| 159 |
form:: |
| 160 |
|
| 161 |
from django.db import models |
| 162 |
|
| 163 |
Medal = models.TextChoices("Medal", "GOLD SILVER BRONZE") |
| 164 |
|
| 165 |
SPORT_CHOICES = [ |
| 166 |
("Martial Arts", [("judo", "Judo"), ("karate", "Karate")]), |
| 167 |
("Racket", [("badminton", "Badminton"), ("tennis", "Tennis")]), |
| 168 |
("unknown", "Unknown"), |
| 169 |
] |
| 170 |
|
| 171 |
|
| 172 |
class Winner(models.Model): |
| 173 |
name = models.CharField(...) |
| 174 |
medal = models.CharField(..., choices=Medal.choices) |
| 175 |
sport = models.CharField(..., choices=SPORT_CHOICES) |
| 176 |
|
| 177 |
Django 5.0 adds support for accepting a mapping or a callable instead of an |
| 178 |
iterable, and also no longer requires ``.choices`` to be used directly to |
| 179 |
expand :ref:`enumeration types <field-choices-enum-types>`:: |
| 180 |
|
| 181 |
from django.db import models |
| 182 |
|
| 183 |
Medal = models.TextChoices("Medal", "GOLD SILVER BRONZE") |
| 184 |
|
| 185 |
SPORT_CHOICES = { # Using a mapping instead of a list of 2-tuples. |
| 186 |
"Martial Arts": {"judo": "Judo", "karate": "Karate"}, |
| 187 |
"Racket": {"badminton": "Badminton", "tennis": "Tennis"}, |
| 188 |
"unknown": "Unknown", |
| 189 |
} |
| 190 |
|
| 191 |
|
| 192 |
def get_scores(): |
| 193 |
return [(i, str(i)) for i in range(10)] |
| 194 |
|
| 195 |
|
| 196 |
class Winner(models.Model): |
| 197 |
name = models.CharField(...) |
| 198 |
medal = models.CharField(..., choices=Medal) # Using `.choices` not required. |
| 199 |
sport = models.CharField(..., choices=SPORT_CHOICES) |
| 200 |
score = models.IntegerField(choices=get_scores) # A callable is allowed. |
| 201 |
|
| 202 |
Under the hood the provided ``choices`` are normalized into a list of 2-tuples |
| 203 |
as the canonical form whenever the ``choices`` value is updated. For more |
| 204 |
information, please check the :ref:`model field reference on choices |
| 205 |
<field-choices>`. |
| 206 |
|
| 207 |
Minor features |
| 208 |
-------------- |
| 209 |
|
| 210 |
:mod:`django.contrib.admin` |
| 211 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 212 |
|
| 213 |
* The new :meth:`.AdminSite.get_log_entries` method allows customizing the |
| 214 |
queryset for the site's listed log entries. |
| 215 |
|
| 216 |
* The ``django.contrib.admin.AllValuesFieldListFilter``, |
| 217 |
``ChoicesFieldListFilter``, ``RelatedFieldListFilter``, and |
| 218 |
``RelatedOnlyFieldListFilter`` admin filters now handle multi-valued query |
| 219 |
parameters. |
| 220 |
|
| 221 |
* ``XRegExp`` is upgraded from version 3.2.0 to 5.1.1. |
| 222 |
|
| 223 |
* The new :meth:`.AdminSite.get_model_admin` method returns an admin class for |
| 224 |
the given model class. |
| 225 |
|
| 226 |
* Properties in :attr:`.ModelAdmin.list_display` now support ``boolean`` |
| 227 |
attribute. |
| 228 |
|
| 229 |
* jQuery is upgraded from version 3.6.4 to 3.7.1. |
| 230 |
|
| 231 |
|
| 232 |
:mod:`django.contrib.auth` |
| 233 |
~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 234 |
|
| 235 |
* The default iteration count for the PBKDF2 password hasher is increased from |
| 236 |
600,000 to 720,000. |
| 237 |
|
| 238 |
* The new asynchronous functions are now provided, using an |
| 239 |
``a`` prefix: :func:`django.contrib.auth.aauthenticate`, |
| 240 |
:func:`~.django.contrib.auth.aget_user`, |
| 241 |
:func:`~.django.contrib.auth.alogin`, :func:`~.django.contrib.auth.alogout`, |
| 242 |
and :func:`~.django.contrib.auth.aupdate_session_auth_hash`. |
| 243 |
|
| 244 |
* ``AuthenticationMiddleware`` now adds an :meth:`.HttpRequest.auser` |
| 245 |
asynchronous method that returns the currently logged-in user. |
| 246 |
|
| 247 |
* The new :func:`django.contrib.auth.hashers.acheck_password` asynchronous |
| 248 |
function and :meth:`.AbstractBaseUser.acheck_password` method allow |
| 249 |
asynchronous checking of user passwords. |
| 250 |
|
| 251 |
:mod:`django.contrib.contenttypes` |
| 252 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 253 |
|
| 254 |
* :meth:`.QuerySet.prefetch_related` now supports prefetching |
| 255 |
:class:`~django.contrib.contenttypes.fields.GenericForeignKey` with |
| 256 |
non-homogeneous set of results. |
| 257 |
|
| 258 |
:mod:`django.contrib.gis` |
| 259 |
~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 260 |
|
| 261 |
* The new |
| 262 |
:class:`ClosestPoint() <django.contrib.gis.db.models.functions.ClosestPoint>` |
| 263 |
function returns a 2-dimensional point on the geometry that is closest to |
| 264 |
another geometry. |
| 265 |
|
| 266 |
* :ref:`GIS aggregates <gis-aggregation-functions>` now support the ``filter`` |
| 267 |
argument. |
| 268 |
|
| 269 |
* Support for GDAL 3.7 and GEOS 3.12 is added. |
| 270 |
|
| 271 |
* The new :meth:`.GEOSGeometry.equals_identical` method allows point-wise |
| 272 |
equivalence checking of geometries. |
| 273 |
|
| 274 |
:mod:`django.contrib.messages` |
| 275 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 276 |
|
| 277 |
* The new :meth:`.MessagesTestMixin.assertMessages` assertion method allows |
| 278 |
testing :mod:`~django.contrib.messages` added to a |
| 279 |
:class:`response <django.http.HttpResponse>`. |
| 280 |
|
| 281 |
:mod:`django.contrib.postgres` |
| 282 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 283 |
|
| 284 |
* The new :attr:`~.ExclusionConstraint.violation_error_code` attribute of |
| 285 |
:class:`~django.contrib.postgres.constraints.ExclusionConstraint` allows |
| 286 |
customizing the ``code`` of ``ValidationError`` raised during |
| 287 |
:ref:`model validation <validating-objects>`. |
| 288 |
|
| 289 |
Asynchronous views |
| 290 |
~~~~~~~~~~~~~~~~~~ |
| 291 |
|
| 292 |
* Under ASGI, ``http.disconnect`` events are now handled. This allows views to |
| 293 |
perform any necessary cleanup if a client disconnects before the response is |
| 294 |
generated. See :ref:`async-handling-disconnect` for more details. |
| 295 |
|
| 296 |
Decorators |
| 297 |
~~~~~~~~~~ |
| 298 |
|
| 299 |
* The following decorators now support wrapping asynchronous view functions: |
| 300 |
|
| 301 |
* :func:`~django.views.decorators.cache.cache_control` |
| 302 |
* :func:`~django.views.decorators.cache.never_cache` |
| 303 |
* :func:`~django.views.decorators.common.no_append_slash` |
| 304 |
* :func:`~django.views.decorators.csrf.csrf_exempt` |
| 305 |
* :func:`~django.views.decorators.csrf.csrf_protect` |
| 306 |
* :func:`~django.views.decorators.csrf.ensure_csrf_cookie` |
| 307 |
* :func:`~django.views.decorators.csrf.requires_csrf_token` |
| 308 |
* :func:`~django.views.decorators.debug.sensitive_variables` |
| 309 |
* :func:`~django.views.decorators.debug.sensitive_post_parameters` |
| 310 |
* :func:`~django.views.decorators.gzip.gzip_page` |
| 311 |
* :func:`~django.views.decorators.http.condition` |
| 312 |
* ``conditional_page()`` |
| 313 |
* :func:`~django.views.decorators.http.etag` |
| 314 |
* :func:`~django.views.decorators.http.last_modified` |
| 315 |
* :func:`~django.views.decorators.http.require_http_methods` |
| 316 |
* :func:`~django.views.decorators.http.require_GET` |
| 317 |
* :func:`~django.views.decorators.http.require_POST` |
| 318 |
* :func:`~django.views.decorators.http.require_safe` |
| 319 |
* :func:`~django.views.decorators.vary.vary_on_cookie` |
| 320 |
* :func:`~django.views.decorators.vary.vary_on_headers` |
| 321 |
* ``xframe_options_deny()`` |
| 322 |
* ``xframe_options_sameorigin()`` |
| 323 |
* ``xframe_options_exempt()`` |
| 324 |
|
| 325 |
Error Reporting |
| 326 |
~~~~~~~~~~~~~~~ |
| 327 |
|
| 328 |
* :func:`~django.views.decorators.debug.sensitive_variables` and |
| 329 |
:func:`~django.views.decorators.debug.sensitive_post_parameters` can now be |
| 330 |
used with asynchronous functions. |
| 331 |
|
| 332 |
File Storage |
| 333 |
~~~~~~~~~~~~ |
| 334 |
|
| 335 |
* :meth:`.File.open` now passes all positional (``*args``) and keyword |
| 336 |
arguments (``**kwargs``) to Python's built-in :func:`python:open`. |
| 337 |
|
| 338 |
Forms |
| 339 |
~~~~~ |
| 340 |
|
| 341 |
* The new :attr:`~django.forms.URLField.assume_scheme` argument for |
| 342 |
:class:`~django.forms.URLField` allows specifying a default URL scheme. |
| 343 |
|
| 344 |
* In order to improve accessibility, the following changes are made: |
| 345 |
|
| 346 |
* Form fields now include the ``aria-describedby`` HTML attribute to enable |
| 347 |
screen readers to associate form fields with their help text. |
| 348 |
* Invalid form fields now include the ``aria-invalid="true"`` HTML attribute. |
| 349 |
|
| 350 |
Internationalization |
| 351 |
~~~~~~~~~~~~~~~~~~~~ |
| 352 |
|
| 353 |
* Support and translations for the Uyghur language are now available. |
| 354 |
|
| 355 |
Migrations |
| 356 |
~~~~~~~~~~ |
| 357 |
|
| 358 |
* Serialization of functions decorated with :func:`functools.cache` or |
| 359 |
:func:`functools.lru_cache` is now supported without the need to write a |
| 360 |
custom serializer. |
| 361 |
|
| 362 |
Models |
| 363 |
~~~~~~ |
| 364 |
|
| 365 |
* The new ``create_defaults`` argument of :meth:`.QuerySet.update_or_create` |
| 366 |
and :meth:`.QuerySet.aupdate_or_create` methods allows specifying a different |
| 367 |
field values for the create operation. |
| 368 |
|
| 369 |
* The new ``violation_error_code`` attribute of |
| 370 |
:class:`~django.db.models.BaseConstraint`, |
| 371 |
:class:`~django.db.models.CheckConstraint`, and |
| 372 |
:class:`~django.db.models.UniqueConstraint` allows customizing the ``code`` |
| 373 |
of ``ValidationError`` raised during |
| 374 |
:ref:`model validation <validating-objects>`. |
| 375 |
|
| 376 |
* The :ref:`force_insert <ref-models-force-insert>` argument of |
| 377 |
:meth:`.Model.save` now allows specifying a tuple of parent classes that must |
| 378 |
be forced to be inserted. |
| 379 |
|
| 380 |
* :meth:`.QuerySet.bulk_create` and :meth:`.QuerySet.abulk_create` methods now |
| 381 |
set the primary key on each model instance when the ``update_conflicts`` |
| 382 |
parameter is enabled (if the database supports it). |
| 383 |
|
| 384 |
* The new :attr:`.UniqueConstraint.nulls_distinct` attribute allows customizing |
| 385 |
the treatment of ``NULL`` values on PostgreSQL 15+. |
| 386 |
|
| 387 |
* The new :func:`~django.shortcuts.aget_object_or_404` and |
| 388 |
:func:`~django.shortcuts.aget_list_or_404` asynchronous shortcuts allow |
| 389 |
asynchronous getting objects. |
| 390 |
|
| 391 |
* The new :func:`~django.db.models.aprefetch_related_objects` function allows |
| 392 |
asynchronous prefetching of model instances. |
| 393 |
|
| 394 |
* :meth:`.QuerySet.aiterator` now supports previous calls to |
| 395 |
``prefetch_related()``. |
| 396 |
|
| 397 |
* On MariaDB 10.7+, ``UUIDField`` is now created as ``UUID`` column rather than |
| 398 |
``CHAR(32)`` column. See the migration guide above for more details on |
| 399 |
:ref:`migrating-uuidfield`. |
| 400 |
|
| 401 |
* Django now supports `oracledb`_ version 1.3.2 or higher. Support for |
| 402 |
``cx_Oracle`` is deprecated as of this release and will be removed in Django |
| 403 |
6.0. |
| 404 |
|
| 405 |
Pagination |
| 406 |
~~~~~~~~~~ |
| 407 |
|
| 408 |
* The new :attr:`django.core.paginator.Paginator.error_messages` argument |
| 409 |
allows customizing the error messages raised by :meth:`.Paginator.page`. |
| 410 |
|
| 411 |
Signals |
| 412 |
~~~~~~~ |
| 413 |
|
| 414 |
* The new :meth:`.Signal.asend` and :meth:`.Signal.asend_robust` methods allow |
| 415 |
asynchronous signal dispatch. Signal receivers may be synchronous or |
| 416 |
asynchronous, and will be automatically adapted to the correct calling style. |
| 417 |
|
| 418 |
Templates |
| 419 |
~~~~~~~~~ |
| 420 |
|
| 421 |
* The new :tfilter:`escapeseq` template filter applies :tfilter:`escape` to |
| 422 |
each element of a sequence. |
| 423 |
|
| 424 |
Tests |
| 425 |
~~~~~ |
| 426 |
|
| 427 |
* :class:`~django.test.Client` and :class:`~django.test.AsyncClient` now |
| 428 |
provide asynchronous methods, using an ``a`` prefix: |
| 429 |
:meth:`~django.test.Client.asession`, :meth:`~django.test.Client.alogin`, |
| 430 |
:meth:`~django.test.Client.aforce_login`, and |
| 431 |
:meth:`~django.test.Client.alogout`. |
| 432 |
|
| 433 |
* :class:`~django.test.AsyncClient` now supports the ``follow`` parameter. |
| 434 |
|
| 435 |
* :class:`~django.test.runner.DiscoverRunner` now allows showing the duration |
| 436 |
of the slowest tests using the :option:`test --durations` option (available |
| 437 |
on Python 3.12+). |
| 438 |
|
| 439 |
Validators |
| 440 |
~~~~~~~~~~ |
| 441 |
|
| 442 |
* The new ``offset`` argument of |
| 443 |
:class:`~django.core.validators.StepValueValidator` allows specifying an |
| 444 |
offset for valid values. |
| 445 |
|
| 446 |
.. _backwards-incompatible-5.0: |
| 447 |
|
| 448 |
Backwards incompatible changes in 5.0 |
| 449 |
===================================== |
| 450 |
|
| 451 |
Database backend API |
| 452 |
-------------------- |
| 453 |
|
| 454 |
This section describes changes that may be needed in third-party database |
| 455 |
backends. |
| 456 |
|
| 457 |
* ``DatabaseFeatures.supports_expression_defaults`` should be set to ``False`` |
| 458 |
if the database doesn't support using database functions as defaults. |
| 459 |
|
| 460 |
* ``DatabaseFeatures.supports_default_keyword_in_insert`` should be set to |
| 461 |
``False`` if the database doesn't support the ``DEFAULT`` keyword in |
| 462 |
``INSERT`` queries. |
| 463 |
|
| 464 |
* ``DatabaseFeatures.supports_default_keyword_in_bulk_insert`` should be set to |
| 465 |
``False`` if the database doesn't support the ``DEFAULT`` keyword in bulk |
| 466 |
``INSERT`` queries. |
| 467 |
|
| 468 |
:mod:`django.contrib.gis` |
| 469 |
------------------------- |
| 470 |
|
| 471 |
* Support for GDAL 2.2 and 2.3 is removed. |
| 472 |
|
| 473 |
* Support for GEOS 3.6 and 3.7 is removed. |
| 474 |
|
| 475 |
:mod:`django.contrib.sitemaps` |
| 476 |
------------------------------ |
| 477 |
|
| 478 |
* The ``django.contrib.sitemaps.ping_google()`` function and the |
| 479 |
``ping_google`` management command are removed as the Google |
| 480 |
Sitemaps ping endpoint is deprecated and will be removed in January 2024. |
| 481 |
|
| 482 |
* The ``django.contrib.sitemaps.SitemapNotFound`` exception class is removed. |
| 483 |
|
| 484 |
Dropped support for MySQL < 8.0.11 |
| 485 |
---------------------------------- |
| 486 |
|
| 487 |
Support for pre-releases of MySQL 8.0.x series is removed. Django 5.0 supports |
| 488 |
MySQL 8.0.11 and higher. |
| 489 |
|
| 490 |
Using ``create_defaults__exact`` may now be required with ``QuerySet.update_or_create()`` |
| 491 |
----------------------------------------------------------------------------------------- |
| 492 |
|
| 493 |
:meth:`.QuerySet.update_or_create` now supports the parameter |
| 494 |
``create_defaults``. As a consequence, any models that have a field named |
| 495 |
``create_defaults`` that are used with an ``update_or_create()`` should specify |
| 496 |
the field in the lookup with ``create_defaults__exact``. |
| 497 |
|
| 498 |
.. _migrating-uuidfield: |
| 499 |
|
| 500 |
Migrating existing ``UUIDField`` on MariaDB 10.7+ |
| 501 |
------------------------------------------------- |
| 502 |
|
| 503 |
On MariaDB 10.7+, ``UUIDField`` is now created as ``UUID`` column rather than |
| 504 |
``CHAR(32)`` column. As a consequence, any ``UUIDField`` created in |
| 505 |
Django < 5.0 should be replaced with a ``UUIDField`` subclass backed by |
| 506 |
``CHAR(32)``:: |
| 507 |
|
| 508 |
class Char32UUIDField(models.UUIDField): |
| 509 |
def db_type(self, connection): |
| 510 |
return "char(32)" |
| 511 |
|
| 512 |
def get_db_prep_value(self, value, connection, prepared=False): |
| 513 |
value = super().get_db_prep_value(value, connection, prepared) |
| 514 |
if value is not None: |
| 515 |
value = value.hex |
| 516 |
return value |
| 517 |
|
| 518 |
For example:: |
| 519 |
|
| 520 |
class MyModel(models.Model): |
| 521 |
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4) |
| 522 |
|
| 523 |
Should become:: |
| 524 |
|
| 525 |
class Char32UUIDField(models.UUIDField): ... |
| 526 |
|
| 527 |
|
| 528 |
class MyModel(models.Model): |
| 529 |
uuid = Char32UUIDField(primary_key=True, default=uuid.uuid4) |
| 530 |
|
| 531 |
Running the :djadmin:`makemigrations` command will generate a migration |
| 532 |
containing a no-op ``AlterField`` operation. |
| 533 |
|
| 534 |
Miscellaneous |
| 535 |
------------- |
| 536 |
|
| 537 |
* The ``instance`` argument of the undocumented |
| 538 |
``BaseModelFormSet.save_existing()`` method is renamed to ``obj``. |
| 539 |
|
| 540 |
* The undocumented ``django.contrib.admin.helpers.checkbox`` is removed. |
| 541 |
|
| 542 |
* Integer fields are now validated as 64-bit integers on SQLite to match the |
| 543 |
behavior of ``sqlite3``. |
| 544 |
|
| 545 |
* The undocumented ``Query.annotation_select_mask`` attribute is changed from a |
| 546 |
set of strings to an ordered list of strings. |
| 547 |
|
| 548 |
* ``ImageField.update_dimension_fields()`` is no longer called on the |
| 549 |
``post_init`` signal if ``width_field`` and ``height_field`` are not set. |
| 550 |
|
| 551 |
* :class:`~django.db.models.functions.Now` database function now uses |
| 552 |
``LOCALTIMESTAMP`` instead of ``CURRENT_TIMESTAMP`` on Oracle. |
| 553 |
|
| 554 |
* :attr:`.AdminSite.site_header` is now rendered in a ``<div>`` tag instead of |
| 555 |
``<h1>``. Screen reader users rely on heading elements for navigation within |
| 556 |
a page. Having two ``<h1>`` elements was confusing and the site header wasn't |
| 557 |
helpful as it is repeated on all pages. |
| 558 |
|
| 559 |
* In order to improve accessibility, the admin's main content area and header |
| 560 |
content area are now rendered in a ``<main>`` and ``<header>`` tag instead of |
| 561 |
``<div>``. |
| 562 |
|
| 563 |
* On databases without native support for the SQL ``XOR`` operator, ``^`` as |
| 564 |
the exclusive or (``XOR``) operator now returns rows that are matched by an |
| 565 |
odd number of operands rather than exactly one operand. This is consistent |
| 566 |
with the behavior of MySQL, MariaDB, and Python. |
| 567 |
|
| 568 |
* The minimum supported version of ``asgiref`` is increased from 3.6.0 to |
| 569 |
3.7.0. |
| 570 |
|
| 571 |
* The minimum supported version of ``selenium`` is increased from 3.8.0 to |
| 572 |
4.8.0. |
| 573 |
|
| 574 |
* The ``AlreadyRegistered`` and ``NotRegistered`` exceptions are moved from |
| 575 |
``django.contrib.admin.sites`` to ``django.contrib.admin.exceptions``. |
| 576 |
|
| 577 |
* The minimum supported version of SQLite is increased from 3.21.0 to 3.27.0. |
| 578 |
|
| 579 |
* Support for ``cx_Oracle`` < 8.3 is removed. |
| 580 |
|
| 581 |
* Executing SQL queries before the app registry has been fully populated now |
| 582 |
raises :exc:`RuntimeWarning`. |
| 583 |
|
| 584 |
* :exc:`~django.core.exceptions.BadRequest` is raised for non-UTF-8 encoded |
| 585 |
requests with the :mimetype:`application/x-www-form-urlencoded` content type. |
| 586 |
See :rfc:`1866` for more details. |
| 587 |
|
| 588 |
* The minimum supported version of ``colorama`` is increased to 0.4.6. |
| 589 |
|
| 590 |
* The minimum supported version of ``docutils`` is increased to 0.19. |
| 591 |
|
| 592 |
* Filtering querysets against overflowing integer values now always returns an |
| 593 |
empty queryset. As a consequence, you may need to use ``ExpressionWrapper()`` |
| 594 |
to :ref:`explicitly wrap <using-f-with-annotations>` arithmetic against |
| 595 |
integer fields in such cases. |
| 596 |
|
| 597 |
.. _deprecated-features-5.0: |
| 598 |
|
| 599 |
Features deprecated in 5.0 |
| 600 |
========================== |
| 601 |
|
| 602 |
Miscellaneous |
| 603 |
------------- |
| 604 |
|
| 605 |
* The ``DjangoDivFormRenderer`` and ``Jinja2DivFormRenderer`` transitional form |
| 606 |
renderers are deprecated. |
| 607 |
|
| 608 |
* Passing positional arguments ``name`` and ``violation_error_message`` to |
| 609 |
:class:`~django.db.models.BaseConstraint` is deprecated in favor of |
| 610 |
keyword-only arguments. |
| 611 |
|
| 612 |
* ``request`` is added to the signature of :meth:`.ModelAdmin.lookup_allowed`. |
| 613 |
Support for ``ModelAdmin`` subclasses that do not accept this argument is |
| 614 |
deprecated. |
| 615 |
|
| 616 |
* The ``get_joining_columns()`` method of ``ForeignObject`` and |
| 617 |
``ForeignObjectRel`` is deprecated. Starting with Django 6.0, |
| 618 |
``django.db.models.sql.datastructures.Join`` will no longer fallback to |
| 619 |
``get_joining_columns()``. Subclasses should implement |
| 620 |
``get_joining_fields()`` instead. |
| 621 |
|
| 622 |
* The ``ForeignObject.get_reverse_joining_columns()`` method is deprecated. |
| 623 |
|
| 624 |
* The default scheme for ``forms.URLField`` will change from ``"http"`` to |
| 625 |
``"https"`` in Django 6.0. Set :setting:`FORMS_URLFIELD_ASSUME_HTTPS` |
| 626 |
transitional setting to ``True`` to opt into assuming ``"https"`` during the |
| 627 |
Django 5.x release cycle. |
| 628 |
|
| 629 |
* ``FORMS_URLFIELD_ASSUME_HTTPS`` transitional setting is deprecated. |
| 630 |
|
| 631 |
* Support for calling ``format_html()`` without passing args or kwargs is |
| 632 |
deprecated. |
| 633 |
|
| 634 |
* Support for ``cx_Oracle`` is deprecated in favor of `oracledb`_ 1.3.2+ Python |
| 635 |
driver. |
| 636 |
|
| 637 |
* ``DatabaseOperations.field_cast_sql()`` is deprecated in favor of |
| 638 |
``DatabaseOperations.lookup_cast()``. Starting with Django 6.0, |
| 639 |
``BuiltinLookup.process_lhs()`` will no longer call ``field_cast_sql()``. |
| 640 |
Third-party database backends should implement ``lookup_cast()`` instead. |
| 641 |
|
| 642 |
* The ``django.db.models.enums.ChoicesMeta`` metaclass is renamed to |
| 643 |
``ChoicesType``. |
| 644 |
|
| 645 |
* The ``Prefetch.get_current_queryset()`` method is deprecated. |
| 646 |
|
| 647 |
* The ``get_prefetch_queryset()`` method of related managers and descriptors |
| 648 |
is deprecated. Starting with Django 6.0, ``get_prefetcher()`` and |
| 649 |
``prefetch_related_objects()`` will no longer fallback to |
| 650 |
``get_prefetch_queryset()``. Subclasses should implement |
| 651 |
``get_prefetch_querysets()`` instead. |
| 652 |
|
| 653 |
.. _`oracledb`: https://oracle.github.io/python-oracledb/ |
| 654 |
|
| 655 |
Features removed in 5.0 |
| 656 |
======================= |
| 657 |
|
| 658 |
These features have reached the end of their deprecation cycle and are removed |
| 659 |
in Django 5.0. |
| 660 |
|
| 661 |
See :ref:`deprecated-features-4.0` for details on these changes, including how |
| 662 |
to remove usage of these features. |
| 663 |
|
| 664 |
* The ``SERIALIZE`` test setting is removed. |
| 665 |
|
| 666 |
* The undocumented ``django.utils.baseconv`` module is removed. |
| 667 |
|
| 668 |
* The undocumented ``django.utils.datetime_safe`` module is removed. |
| 669 |
|
| 670 |
* The default value of the ``USE_TZ`` setting is changed from ``False`` to |
| 671 |
``True``. |
| 672 |
|
| 673 |
* The default sitemap protocol for sitemaps built outside the context of a |
| 674 |
request is changed from ``'http'`` to ``'https'``. |
| 675 |
|
| 676 |
* The ``extra_tests`` argument for ``DiscoverRunner.build_suite()`` and |
| 677 |
``DiscoverRunner.run_tests()`` is removed. |
| 678 |
|
| 679 |
* The ``django.contrib.postgres.aggregates.ArrayAgg``, ``JSONBAgg``, and |
| 680 |
``StringAgg`` aggregates no longer return ``[]``, ``[]``, and ``''``, |
| 681 |
respectively, when there are no rows. |
| 682 |
|
| 683 |
* The ``USE_L10N`` setting is removed. |
| 684 |
|
| 685 |
* The ``USE_DEPRECATED_PYTZ`` transitional setting is removed. |
| 686 |
|
| 687 |
* Support for ``pytz`` timezones is removed. |
| 688 |
|
| 689 |
* The ``is_dst`` argument is removed from: |
| 690 |
|
| 691 |
* ``QuerySet.datetimes()`` |
| 692 |
* ``django.utils.timezone.make_aware()`` |
| 693 |
* ``django.db.models.functions.Trunc()`` |
| 694 |
* ``django.db.models.functions.TruncSecond()`` |
| 695 |
* ``django.db.models.functions.TruncMinute()`` |
| 696 |
* ``django.db.models.functions.TruncHour()`` |
| 697 |
* ``django.db.models.functions.TruncDay()`` |
| 698 |
* ``django.db.models.functions.TruncWeek()`` |
| 699 |
* ``django.db.models.functions.TruncMonth()`` |
| 700 |
* ``django.db.models.functions.TruncQuarter()`` |
| 701 |
* ``django.db.models.functions.TruncYear()`` |
| 702 |
|
| 703 |
* The ``django.contrib.gis.admin.GeoModelAdmin`` and ``OSMGeoAdmin`` classes |
| 704 |
are removed. |
| 705 |
|
| 706 |
* The undocumented ``BaseForm._html_output()`` method is removed. |
| 707 |
|
| 708 |
* The ability to return a ``str``, rather than a ``SafeString``, when rendering |
| 709 |
an ``ErrorDict`` and ``ErrorList`` is removed. |
| 710 |
|
| 711 |
See :ref:`deprecated-features-4.1` for details on these changes, including how |
| 712 |
to remove usage of these features. |
| 713 |
|
| 714 |
* The ``SitemapIndexItem.__str__()`` method is removed. |
| 715 |
|
| 716 |
* The ``CSRF_COOKIE_MASKED`` transitional setting is removed. |
| 717 |
|
| 718 |
* The ``name`` argument of ``django.utils.functional.cached_property()`` is |
| 719 |
removed. |
| 720 |
|
| 721 |
* The ``opclasses`` argument of |
| 722 |
``django.contrib.postgres.constraints.ExclusionConstraint`` is removed. |
| 723 |
|
| 724 |
* The undocumented ability to pass ``errors=None`` to |
| 725 |
``SimpleTestCase.assertFormError()`` and ``assertFormsetError()`` is removed. |
| 726 |
|
| 727 |
* ``django.contrib.sessions.serializers.PickleSerializer`` is removed. |
| 728 |
|
| 729 |
* The usage of ``QuerySet.iterator()`` on a queryset that prefetches related |
| 730 |
objects without providing the ``chunk_size`` argument is no longer allowed. |
| 731 |
|
| 732 |
* Passing unsaved model instances to related filters is no longer allowed. |
| 733 |
|
| 734 |
* ``created=True`` is required in the signature of |
| 735 |
``RemoteUserBackend.configure_user()`` subclasses. |
| 736 |
|
| 737 |
* Support for logging out via ``GET`` requests in the |
| 738 |
``django.contrib.auth.views.LogoutView`` and |
| 739 |
``django.contrib.auth.views.logout_then_login()`` is removed. |
| 740 |
|
| 741 |
* The ``django.utils.timezone.utc`` alias to ``datetime.timezone.utc`` is |
| 742 |
removed. |
| 743 |
|
| 744 |
* Passing a response object and a form/formset name to |
| 745 |
``SimpleTestCase.assertFormError()`` and ``assertFormSetError()`` is no |
| 746 |
longer allowed. |
| 747 |
|
| 748 |
* The ``django.contrib.gis.admin.OpenLayersWidget`` is removed. |
| 749 |
|
| 750 |
+ The ``django.contrib.auth.hashers.CryptPasswordHasher`` is removed. |
| 751 |
|
| 752 |
* The ``"django/forms/default.html"`` and |
| 753 |
``"django/forms/formsets/default.html"`` templates are removed. |
| 754 |
|
| 755 |
* The default form and formset rendering style is changed to the div-based. |
| 756 |
|
| 757 |
* Passing ``nulls_first=False`` or ``nulls_last=False`` to ``Expression.asc()`` |
| 758 |
and ``Expression.desc()`` methods, and the ``OrderBy`` expression is no |
| 759 |
longer allowed. |