5.2.txt 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  1. ============================================
  2. Django 5.2 release notes - UNDER DEVELOPMENT
  3. ============================================
  4. *Expected April 2025*
  5. Welcome to Django 5.2!
  6. These release notes cover the :ref:`new features <whats-new-5.2>`, as well as
  7. some :ref:`backwards incompatible changes <backwards-incompatible-5.2>` you
  8. should be aware of when upgrading from Django 5.1 or earlier. We've
  9. :ref:`begun the deprecation process for some features
  10. <deprecated-features-5.2>`.
  11. See the :doc:`/howto/upgrade-version` guide if you're updating an existing
  12. project.
  13. Django 5.2 is designated as a :term:`long-term support release
  14. <Long-term support release>`. It will receive security updates for at least
  15. three years after its release. Support for the previous LTS, Django 4.2, will
  16. end in April 2026.
  17. Python compatibility
  18. ====================
  19. Django 5.2 supports Python 3.10, 3.11, 3.12, and 3.13. We **highly recommend**
  20. and only officially support the latest release of each series.
  21. .. _whats-new-5.2:
  22. What's new in Django 5.2
  23. ========================
  24. Automatic models import in the ``shell``
  25. ----------------------------------------
  26. The :djadmin:`shell` management command now automatically imports models from
  27. all installed apps. You can view further details of the imported objects by
  28. setting the ``--verbosity`` flag to 2 or more:
  29. .. code-block:: pycon
  30. $ python -Wall manage.py shell --verbosity=2
  31. 6 objects imported automatically, including:
  32. from django.contrib.admin.models import LogEntry
  33. from django.contrib.auth.models import Group, Permission, User
  34. from django.contrib.contenttypes.models import ContentType
  35. from django.contrib.sessions.models import Session
  36. This :ref:`behavior can be customized <customizing-shell-auto-imports>` to add
  37. or remove automatic imports.
  38. Composite Primary Keys
  39. ----------------------
  40. The new :class:`django.db.models.CompositePrimaryKey` allows tables to be
  41. created with a primary key consisting of multiple fields.
  42. To use a composite primary key, when defining a model set the ``pk`` attribute
  43. to be a ``CompositePrimaryKey``::
  44. from django.db import models
  45. class Release(models.Model):
  46. pk = models.CompositePrimaryKey("version", "name")
  47. version = models.IntegerField()
  48. name = models.CharField(max_length=20)
  49. See :doc:`/topics/composite-primary-key` for more details.
  50. Minor features
  51. --------------
  52. :mod:`django.contrib.admin`
  53. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  54. * The ``admin/base.html`` template now has a new block
  55. :ref:`extrabody <extrabody>` for adding custom code before the closing
  56. ``</body>`` tag.
  57. * The value of a :class:`~django.db.models.URLField` now renders as a link.
  58. :mod:`django.contrib.admindocs`
  59. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  60. * Links to components in docstrings now supports custom link text, using the
  61. format ``:role:`link text <link>```. See :ref:`documentation helpers
  62. <admindocs-helpers>` for more details.
  63. * The :ref:`model pages <admindocs-model-reference>` are now restricted to
  64. users with the corresponding view or change permissions.
  65. :mod:`django.contrib.auth`
  66. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  67. * The default iteration count for the PBKDF2 password hasher is increased from
  68. 870,000 to 1,000,000.
  69. * The following new asynchronous methods are now provided, using an ``a``
  70. prefix:
  71. * :meth:`.UserManager.acreate_user`
  72. * :meth:`.UserManager.acreate_superuser`
  73. * :meth:`.BaseUserManager.aget_by_natural_key`
  74. * :meth:`.User.aget_user_permissions`
  75. * :meth:`.User.aget_all_permissions`
  76. * :meth:`.User.aget_group_permissions`
  77. * :meth:`.User.ahas_perm`
  78. * :meth:`.User.ahas_perms`
  79. * :meth:`.User.ahas_module_perms`
  80. * :meth:`.User.aget_user_permissions`
  81. * :meth:`.User.aget_group_permissions`
  82. * :meth:`.User.ahas_perm`
  83. * :meth:`.ModelBackend.aauthenticate`
  84. * :meth:`.ModelBackend.aget_user_permissions`
  85. * :meth:`.ModelBackend.aget_group_permissions`
  86. * :meth:`.ModelBackend.aget_all_permissions`
  87. * :meth:`.ModelBackend.ahas_perm`
  88. * :meth:`.ModelBackend.ahas_module_perms`
  89. * :meth:`.RemoteUserBackend.aauthenticate`
  90. * :meth:`.RemoteUserBackend.aconfigure_user`
  91. * Auth backends can now provide async implementations which are used when
  92. calling async auth functions (e.g.
  93. :func:`~.django.contrib.auth.aauthenticate`) to reduce context-switching
  94. which improves performance. See :ref:`adding an async interface
  95. <writing-authentication-backends-async-interface>` for more details.
  96. * The :ref:`password validator classes <included-password-validators>`
  97. now have a new method ``get_error_message()``, which can be overridden in
  98. subclasses to customize the error messages.
  99. :mod:`django.contrib.contenttypes`
  100. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  101. * ...
  102. :mod:`django.contrib.gis`
  103. ~~~~~~~~~~~~~~~~~~~~~~~~~
  104. * GDAL now supports curved geometries ``CurvePolygon``, ``CompoundCurve``,
  105. ``CircularString``, ``MultiSurface``, and ``MultiCurve`` via the new
  106. :attr:`.OGRGeometry.has_curve` property, and the
  107. :meth:`.OGRGeometry.get_linear_geometry` and
  108. :meth:`.OGRGeometry.get_curve_geometry` methods.
  109. * :lookup:`coveredby` and :lookup:`covers` lookup are now supported on MySQL.
  110. * :lookup:`coveredby` and :lookup:`isvalid` lookups,
  111. :class:`~django.contrib.gis.db.models.Collect` aggregation, and
  112. :class:`~django.contrib.gis.db.models.functions.GeoHash` and
  113. :class:`~django.contrib.gis.db.models.functions.IsValid` database functions
  114. are now supported on MariaDB 11.7+.
  115. :mod:`django.contrib.messages`
  116. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  117. * ...
  118. :mod:`django.contrib.postgres`
  119. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  120. * ...
  121. :mod:`django.contrib.redirects`
  122. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  123. * ...
  124. :mod:`django.contrib.sessions`
  125. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  126. * ...
  127. :mod:`django.contrib.sitemaps`
  128. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  129. * ...
  130. :mod:`django.contrib.sites`
  131. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  132. * ...
  133. :mod:`django.contrib.staticfiles`
  134. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  135. * ...
  136. :mod:`django.contrib.syndication`
  137. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  138. * All :class:`~django.utils.feedgenerator.SyndicationFeed` classes now support
  139. a ``stylesheets`` attribute. If specified, an ``<? xml-stylesheet ?>``
  140. processing instruction will be added to the top of the document for each
  141. stylesheet in the given list. See :ref:`feed-stylesheets` for more details.
  142. Asynchronous views
  143. ~~~~~~~~~~~~~~~~~~
  144. * ...
  145. Cache
  146. ~~~~~
  147. * ...
  148. CSRF
  149. ~~~~
  150. * ...
  151. Database backends
  152. ~~~~~~~~~~~~~~~~~
  153. * MySQL connections now default to using the ``utf8mb4`` character set,
  154. instead of ``utf8``, which is an alias for the deprecated character set
  155. ``utf8mb3``.
  156. * Oracle backends now support :ref:`connection pools <oracle-pool>`, by setting
  157. ``"pool"`` in the :setting:`OPTIONS` part of your database configuration.
  158. Decorators
  159. ~~~~~~~~~~
  160. * :func:`~django.utils.decorators.method_decorator` now supports wrapping
  161. asynchronous view methods.
  162. Email
  163. ~~~~~
  164. * Tuple items of :class:`EmailMessage.attachments
  165. <django.core.mail.EmailMessage>` and
  166. :class:`EmailMultiAlternatives.attachments
  167. <django.core.mail.EmailMultiAlternatives>` are now named tuples, as opposed
  168. to regular tuples.
  169. * :attr:`EmailMultiAlternatives.alternatives
  170. <django.core.mail.EmailMultiAlternatives.alternatives>` is now a list of
  171. named tuples, as opposed to regular tuples.
  172. * The new :meth:`~django.core.mail.EmailMultiAlternatives.body_contains` method
  173. returns a boolean indicating whether a provided text is contained in the
  174. email ``body`` and in all attached MIME type ``text/*`` alternatives.
  175. Error Reporting
  176. ~~~~~~~~~~~~~~~
  177. * The attribute :attr:`.SafeExceptionReporterFilter.hidden_settings` now
  178. treats values as sensitive if their name includes ``AUTH``.
  179. File Storage
  180. ~~~~~~~~~~~~
  181. * ...
  182. File Uploads
  183. ~~~~~~~~~~~~
  184. * ...
  185. Forms
  186. ~~~~~
  187. * The new :class:`~django.forms.ColorInput` form widget is for entering a color
  188. in ``rrggbb`` hexadecimal format and renders as ``<input type="color" ...>``.
  189. Some browsers support a visual color picker interface for this input type.
  190. * The new :class:`~django.forms.SearchInput` form widget is for entering search
  191. queries and renders as ``<input type="search" ...>``.
  192. * The new :class:`~django.forms.TelInput` form widget is for entering telephone
  193. numbers and renders as ``<input type="tel" ...>``.
  194. * The new ``field_id`` argument for :class:`~django.forms.ErrorList` allows an
  195. HTML ``id`` attribute to be added in the error template. See
  196. :attr:`.ErrorList.field_id` for details.
  197. * An :attr:`~django.forms.BoundField.aria_describedby` property is added to
  198. ``BoundField`` to ease use of this HTML attribute in templates.
  199. * To improve accessibility for screen reader users ``aria-describedby`` is used
  200. to associated form fields with their error messages. See
  201. :ref:`how form errors are displayed <form-error-display>` for details.
  202. * The new asset object :class:`~django.forms.Script` is available for adding
  203. custom HTML-attributes to JavaScript in form media. See
  204. :ref:`paths as objects <form-media-asset-objects>` for more details.
  205. Generic Views
  206. ~~~~~~~~~~~~~
  207. * ...
  208. Internationalization
  209. ~~~~~~~~~~~~~~~~~~~~
  210. * ...
  211. Logging
  212. ~~~~~~~
  213. * ...
  214. Management Commands
  215. ~~~~~~~~~~~~~~~~~~~
  216. * A new warning is displayed when running :djadmin:`runserver`, indicating that
  217. it is unsuitable for production. This warning can be suppressed by setting
  218. the :envvar:`HIDE_PRODUCTION_WARNING` environment variable to ``"true"``.
  219. * The :djadmin:`makemigrations` and :djadmin:`migrate` commands have a new
  220. ``Command.autodetector`` attribute for subclasses to override in order to use
  221. a custom autodetector class.
  222. * The new :meth:`.BaseCommand.get_check_kwargs` method can be overridden in
  223. custom commands to control the running of system checks, e.g. to opt into
  224. database-dependent checks.
  225. Migrations
  226. ~~~~~~~~~~
  227. * The new operation :class:`.AlterConstraint` is a no-op operation that alters
  228. constraints without dropping and recreating constraints in the database.
  229. Models
  230. ~~~~~~
  231. * The ``SELECT`` clause generated when using :meth:`.QuerySet.values` and
  232. :meth:`.QuerySet.values_list` now matches the specified order of the
  233. referenced expressions. Previously, the order was based of a set of
  234. counterintuitive rules which made query combination through methods such as
  235. :meth:`.QuerySet.union` unpredictable.
  236. * Added support for validation of model constraints which use a
  237. :class:`~django.db.models.GeneratedField`.
  238. * The new :attr:`.Expression.set_returning` attribute specifies that the
  239. expression contains a set-returning function, enforcing subquery evaluation.
  240. This is necessary for many Postgres set-returning functions.
  241. * :attr:`CharField.max_length <django.db.models.CharField.max_length>` is no
  242. longer required to be set on SQLite, which supports unlimited ``VARCHAR``
  243. columns.
  244. * :meth:`.QuerySet.explain` now supports the ``memory`` and ``serialize``
  245. options on PostgreSQL 17+.
  246. * The new :class:`~django.db.models.functions.JSONArray` database function
  247. accepts a list of field names or expressions and returns a JSON array
  248. containing those values.
  249. * The new :attr:`.Expression.allows_composite_expressions` attribute specifies
  250. that the expression allows composite expressions, for example, to support
  251. :ref:`composite primary keys <cpk-and-database-functions>`.
  252. Requests and Responses
  253. ~~~~~~~~~~~~~~~~~~~~~~
  254. * The new :attr:`.HttpResponse.text` property provides the string
  255. representation of :attr:`.HttpResponse.content`.
  256. * The new :meth:`.HttpRequest.get_preferred_type` method can be used to query
  257. the preferred media type the client accepts.
  258. * The new ``preserve_request`` argument for
  259. :class:`~django.http.HttpResponseRedirect` and
  260. :class:`~django.http.HttpResponsePermanentRedirect`
  261. determines whether the HTTP status codes 302/307 or 301/308 are used,
  262. respectively.
  263. * The new ``preserve_request`` argument for
  264. :func:`~django.shortcuts.redirect` allows to instruct the user agent to reuse
  265. the HTTP method and body during redirection using specific status codes.
  266. Security
  267. ~~~~~~~~
  268. * ...
  269. Serialization
  270. ~~~~~~~~~~~~~
  271. * Each serialization format now defines a ``Deserializer`` class, rather than a
  272. function, to improve extensibility when defining a
  273. :ref:`custom serialization format <custom-serialization-formats>`.
  274. Signals
  275. ~~~~~~~
  276. * ...
  277. Templates
  278. ~~~~~~~~~
  279. * The new :meth:`~django.template.Library.simple_block_tag` decorator enables
  280. the creation of simple block tags, which can accept and use a section of the
  281. template.
  282. Tests
  283. ~~~~~
  284. * Stack frames from Django's custom assertions are now hidden. This makes test
  285. failures easier to read and enables :option:`test --pdb` to directly enter
  286. into the failing test method.
  287. * Data loaded from :attr:`~django.test.TransactionTestCase.fixtures` and from
  288. migrations enabled with :ref:`serialized_rollback=True
  289. <test-case-serialized-rollback>` are now available during
  290. ``TransactionTestCase.setUpClass()``.
  291. URLs
  292. ~~~~
  293. * :func:`~django.urls.reverse` now accepts ``query`` and ``fragment`` keyword
  294. arguments, allowing the addition of a query string and/or fragment identifier
  295. in the generated URL, respectively.
  296. Utilities
  297. ~~~~~~~~~
  298. * :class:`~django.utils.safestring.SafeString` now returns
  299. :py:data:`NotImplemented` in ``__add__`` for non-string right-hand side
  300. values. This aligns with the :py:class:`str` addition behavior and allows
  301. ``__radd__`` to be used if available.
  302. * :func:`~django.utils.html.format_html_join` now supports taking an iterable
  303. of mappings, passing their contents as keyword arguments to
  304. :func:`~django.utils.html.format_html`.
  305. Validators
  306. ~~~~~~~~~~
  307. * ...
  308. .. _backwards-incompatible-5.2:
  309. Backwards incompatible changes in 5.2
  310. =====================================
  311. Database backend API
  312. --------------------
  313. This section describes changes that may be needed in third-party database
  314. backends.
  315. * The new :meth:`Model._is_pk_set() <django.db.models.Model._is_pk_set>` method
  316. allows checking if a Model instance's primary key is defined.
  317. * ``BaseDatabaseOperations.adapt_decimalfield_value()`` is now a no-op, simply
  318. returning the given value.
  319. :mod:`django.contrib.gis`
  320. -------------------------
  321. * Support for PostGIS 3.0 is removed.
  322. * Support for GDAL 3.0 is removed.
  323. Dropped support for PostgreSQL 13
  324. ---------------------------------
  325. Upstream support for PostgreSQL 13 ends in November 2025. Django 5.2 supports
  326. PostgreSQL 14 and higher.
  327. Changed MySQL connection character set default
  328. ----------------------------------------------
  329. MySQL connections now default to using the ``utf8mb4`` character set, instead
  330. of ``utf8``, which is an alias for the deprecated character set ``utf8mb3``.
  331. ``utf8mb3`` can be specified in the ``OPTIONS`` part of the ``DATABASES``
  332. setting, if needed for legacy databases.
  333. Miscellaneous
  334. -------------
  335. * Adding :attr:`.EmailMultiAlternatives.alternatives` is now only supported via
  336. the :meth:`~.EmailMultiAlternatives.attach_alternative` method.
  337. * The minimum supported version of ``gettext`` is increased from 0.15 to 0.19.
  338. * ``HttpRequest.accepted_types`` is now sorted by the client's preference,
  339. based on the request's ``Accept`` header.
  340. * The attributes :attr:`.UniqueConstraint.violation_error_code` and
  341. :attr:`.UniqueConstraint.violation_error_message` are now always used when
  342. provided. Previously, they were ignored if :attr:`.UniqueConstraint.fields`
  343. was set without a :attr:`.UniqueConstraint.condition`.
  344. * The :func:`~django.template.context_processors.debug` context processor is no
  345. longer included in the default project template.
  346. * The following methods now have ``alters_data=True`` set to prevent side
  347. effects when :ref:`rendering a template context <alters-data-description>`:
  348. * :meth:`.UserManager.create_user`
  349. * :meth:`.UserManager.acreate_user`
  350. * :meth:`.UserManager.create_superuser`
  351. * :meth:`.UserManager.acreate_superuser`
  352. * :meth:`.QuerySet.create`
  353. * :meth:`.QuerySet.acreate`
  354. * :meth:`.QuerySet.bulk_create`
  355. * :meth:`.QuerySet.abulk_create`
  356. * :meth:`.QuerySet.get_or_create`
  357. * :meth:`.QuerySet.aget_or_create`
  358. * :meth:`.QuerySet.update_or_create`
  359. * :meth:`.QuerySet.aupdate_or_create`
  360. * The minimum supported version of ``oracledb`` is increased from 1.3.2 to
  361. 2.3.0.
  362. * Built-in aggregate functions accepting only one argument (``Avg``, ``Count``,
  363. ``Max``, ``Min``, ``StdDev``, ``Sum``, and ``Variance``) now raise
  364. :exc:`TypeError` when called with an incorrect number of arguments.
  365. .. _deprecated-features-5.2:
  366. Features deprecated in 5.2
  367. ==========================
  368. Miscellaneous
  369. -------------
  370. * The ``all`` argument for the ``django.contrib.staticfiles.finders.find()``
  371. function is deprecated in favor of the ``find_all`` argument.
  372. * The fallback to ``request.user`` when ``user`` is ``None`` in
  373. ``django.contrib.auth.login()`` and ``django.contrib.auth.alogin()`` will be
  374. removed.
  375. * The ``ordering`` keyword argument of the PostgreSQL specific aggregation
  376. functions ``django.contrib.postgres.aggregates.ArrayAgg``,
  377. ``django.contrib.postgres.aggregates.JSONBAgg``, and
  378. ``django.contrib.postgres.aggregates.StringAgg`` is deprecated in favor
  379. of the ``order_by`` argument.