5.2.txt 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  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. Minor features
  25. --------------
  26. :mod:`django.contrib.admin`
  27. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  28. * The ``admin/base.html`` template now has a new block
  29. :ref:`extrabody <extrabody>` for adding custom code before the closing
  30. ``</body>`` tag.
  31. :mod:`django.contrib.admindocs`
  32. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  33. * Links to components in docstrings now supports custom link text, using the
  34. format ``:role:`link text <link>```. See :ref:`documentation helpers
  35. <admindocs-helpers>` for more details.
  36. * The :ref:`model pages <admindocs-model-reference>` are now restricted to only
  37. allow access to users with the corresponding model view or change permissions.
  38. :mod:`django.contrib.auth`
  39. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  40. * The default iteration count for the PBKDF2 password hasher is increased from
  41. 870,000 to 1,000,000.
  42. * The following new asynchronous methods are now provided, using an ``a``
  43. prefix:
  44. * :meth:`.UserManager.acreate_user`
  45. * :meth:`.UserManager.acreate_superuser`
  46. * :meth:`.BaseUserManager.aget_by_natural_key`
  47. * :meth:`.User.aget_user_permissions`
  48. * :meth:`.User.aget_all_permissions`
  49. * :meth:`.User.aget_group_permissions`
  50. * :meth:`.User.ahas_perm`
  51. * :meth:`.User.ahas_perms`
  52. * :meth:`.User.ahas_module_perms`
  53. * :meth:`.User.aget_user_permissions`
  54. * :meth:`.User.aget_group_permissions`
  55. * :meth:`.User.ahas_perm`
  56. * :meth:`.ModelBackend.aauthenticate`
  57. * :meth:`.ModelBackend.aget_user_permissions`
  58. * :meth:`.ModelBackend.aget_group_permissions`
  59. * :meth:`.ModelBackend.aget_all_permissions`
  60. * :meth:`.ModelBackend.ahas_perm`
  61. * :meth:`.ModelBackend.ahas_module_perms`
  62. * :meth:`.RemoteUserBackend.aauthenticate`
  63. * :meth:`.RemoteUserBackend.aconfigure_user`
  64. * Auth backends can now provide async implementations which are used when
  65. calling async auth functions (e.g.
  66. :func:`~.django.contrib.auth.aauthenticate`) to reduce context-switching which
  67. improves performance. See :ref:`adding an async interface
  68. <writing-authentication-backends-async-interface>` for more details.
  69. * The :ref:`password validator classes <included-password-validators>`
  70. now have a new method ``get_error_message()``, which can be overridden in
  71. subclasses to customize the error messages.
  72. :mod:`django.contrib.contenttypes`
  73. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  74. * ...
  75. :mod:`django.contrib.gis`
  76. ~~~~~~~~~~~~~~~~~~~~~~~~~
  77. * GDAL now supports curved geometries ``CurvePolygon``, ``CompoundCurve``,
  78. ``CircularString``, ``MultiSurface``, and ``MultiCurve`` via the new
  79. :attr:`.OGRGeometry.has_curve` property, and the
  80. :meth:`.OGRGeometry.get_linear_geometry` and
  81. :meth:`.OGRGeometry.get_curve_geometry` methods.
  82. * :lookup:`coveredby` and :lookup:`covers` lookup are now supported on MySQL.
  83. * :lookup:`coveredby` and :lookup:`isvalid` lookups,
  84. :class:`~django.contrib.gis.db.models.Collect` aggregation, and
  85. :class:`~django.contrib.gis.db.models.functions.GeoHash` and
  86. :class:`~django.contrib.gis.db.models.functions.IsValid` database functions
  87. are now supported on MariaDB 11.7+.
  88. :mod:`django.contrib.messages`
  89. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  90. * ...
  91. :mod:`django.contrib.postgres`
  92. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  93. * ...
  94. :mod:`django.contrib.redirects`
  95. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  96. * ...
  97. :mod:`django.contrib.sessions`
  98. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  99. * ...
  100. :mod:`django.contrib.sitemaps`
  101. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  102. * ...
  103. :mod:`django.contrib.sites`
  104. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  105. * ...
  106. :mod:`django.contrib.staticfiles`
  107. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  108. * ...
  109. :mod:`django.contrib.syndication`
  110. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  111. * All :class:`~django.utils.feedgenerator.SyndicationFeed` classes now support
  112. a ``stylesheets`` attribute. If specified, an ``<? xml-stylesheet ?>``
  113. processing instruction will be added to the top of the document for each
  114. stylesheet in the given list. See :ref:`feed-stylesheets` for more details.
  115. Asynchronous views
  116. ~~~~~~~~~~~~~~~~~~
  117. * ...
  118. Cache
  119. ~~~~~
  120. * ...
  121. CSRF
  122. ~~~~
  123. * ...
  124. Database backends
  125. ~~~~~~~~~~~~~~~~~
  126. * ...
  127. Decorators
  128. ~~~~~~~~~~
  129. * :func:`~django.utils.decorators.method_decorator` now supports wrapping
  130. asynchronous view methods.
  131. Email
  132. ~~~~~
  133. * Tuple items of :class:`EmailMessage.attachments
  134. <django.core.mail.EmailMessage>` and
  135. :class:`EmailMultiAlternatives.attachments
  136. <django.core.mail.EmailMultiAlternatives>` are now named tuples, as opposed
  137. to regular tuples.
  138. * :attr:`EmailMultiAlternatives.alternatives
  139. <django.core.mail.EmailMultiAlternatives.alternatives>` is now a list of
  140. named tuples, as opposed to regular tuples.
  141. * The new :meth:`~django.core.mail.EmailMultiAlternatives.body_contains` method
  142. returns a boolean indicating whether a provided text is contained in the
  143. email ``body`` and in all attached MIME type ``text/*`` alternatives.
  144. Error Reporting
  145. ~~~~~~~~~~~~~~~
  146. * The attribute :attr:`.SafeExceptionReporterFilter.hidden_settings` now
  147. treats values as sensitive if their name includes ``AUTH``.
  148. File Storage
  149. ~~~~~~~~~~~~
  150. * ...
  151. File Uploads
  152. ~~~~~~~~~~~~
  153. * ...
  154. Forms
  155. ~~~~~
  156. * The new :class:`~django.forms.ColorInput` form widget is for entering a color
  157. in ``rrggbb`` hexadecimal format and renders as ``<input type="color" ...>``.
  158. Some browsers support a visual color picker interface for this input type.
  159. * The new :class:`~django.forms.SearchInput` form widget is for entering search
  160. queries and renders as ``<input type="search" ...>``.
  161. * The new :class:`~django.forms.TelInput` form widget is for entering telephone
  162. numbers and renders as ``<input type="tel" ...>``.
  163. Generic Views
  164. ~~~~~~~~~~~~~
  165. * ...
  166. Internationalization
  167. ~~~~~~~~~~~~~~~~~~~~
  168. * ...
  169. Logging
  170. ~~~~~~~
  171. * ...
  172. Management Commands
  173. ~~~~~~~~~~~~~~~~~~~
  174. * A new warning is printed to the console when running :djadmin:`runserver` that
  175. ``runserver`` is unsuitable for production. This warning can be hidden by
  176. setting the :envvar:`HIDE_PRODUCTION_WARNING` environment variable to
  177. ``"true"``.
  178. * The :djadmin:`makemigrations` and :djadmin:`migrate` commands have a new
  179. ``Command.autodetector`` attribute for subclasses to override in order to use
  180. a custom autodetector class.
  181. Migrations
  182. ~~~~~~~~~~
  183. * ...
  184. Models
  185. ~~~~~~
  186. * The ``SELECT`` clause generated when using
  187. :meth:`QuerySet.values()<django.db.models.query.QuerySet.values>` and
  188. :meth:`~django.db.models.query.QuerySet.values_list` now matches the
  189. specified order of the referenced expressions. Previously the order was based
  190. of a set of counterintuitive rules which made query combination through
  191. methods such as
  192. :meth:`QuerySet.union()<django.db.models.query.QuerySet.union>` unpredictable.
  193. * Added support for validation of model constraints which use a
  194. :class:`~django.db.models.GeneratedField`.
  195. * The new :attr:`.Expression.set_returning` attribute specifies that the
  196. expression contains a set-returning function, enforcing subquery evaluation.
  197. This is necessary for many Postgres set-returning functions.
  198. * :attr:`CharField.max_length <django.db.models.CharField.max_length>` is no
  199. longer required to be set on SQLite, which supports unlimited ``VARCHAR``
  200. columns.
  201. * :meth:`.QuerySet.explain` now supports the ``memory`` and ``serialize``
  202. options on PostgreSQL 17+.
  203. Requests and Responses
  204. ~~~~~~~~~~~~~~~~~~~~~~
  205. * The new :attr:`.HttpResponse.text` property provides the string representation
  206. of :attr:`.HttpResponse.content`.
  207. * The new :meth:`.HttpRequest.get_preferred_type` method can be used to query
  208. the preferred media type the client accepts.
  209. Security
  210. ~~~~~~~~
  211. * ...
  212. Serialization
  213. ~~~~~~~~~~~~~
  214. * Each serialization format now defines a ``Deserializer`` class, rather than a
  215. function, to improve extensibility when defining a
  216. :ref:`custom serialization format <custom-serialization-formats>`.
  217. Signals
  218. ~~~~~~~
  219. * ...
  220. Templates
  221. ~~~~~~~~~
  222. * ...
  223. Tests
  224. ~~~~~
  225. * Stack frames from Django's custom assertions are now hidden. This makes test
  226. failures easier to read and enables :option:`test --pdb` to directly enter
  227. into the failing test method.
  228. * Data loaded from :attr:`~django.test.TransactionTestCase.fixtures` and from
  229. migrations enabled with :ref:`serialized_rollback=True
  230. <test-case-serialized-rollback>` are now available during
  231. ``TransactionTestCase.setUpClass()``.
  232. URLs
  233. ~~~~
  234. * ...
  235. Utilities
  236. ~~~~~~~~~
  237. * :class:`~django.utils.safestring.SafeString` now returns
  238. :py:data:`NotImplemented` in ``__add__`` for non-string right-hand side
  239. values. This aligns with the :py:class:`str` addition behavior and allows
  240. ``__radd__`` to be used if available.
  241. * :func:`~django.utils.html.format_html_join` now supports taking an iterable
  242. of mappings, passing their contents as keyword arguments to
  243. :func:`~django.utils.html.format_html`.
  244. Validators
  245. ~~~~~~~~~~
  246. * ...
  247. .. _backwards-incompatible-5.2:
  248. Backwards incompatible changes in 5.2
  249. =====================================
  250. Database backend API
  251. --------------------
  252. This section describes changes that may be needed in third-party database
  253. backends.
  254. * The new :meth:`Model._is_pk_set() <django.db.models.Model._is_pk_set>` method
  255. allows checking if a Model instance's primary key is defined.
  256. :mod:`django.contrib.gis`
  257. -------------------------
  258. * Support for PostGIS 3.0 is removed.
  259. * Support for GDAL 3.0 is removed.
  260. Dropped support for PostgreSQL 13
  261. ---------------------------------
  262. Upstream support for PostgreSQL 13 ends in November 2025. Django 5.2 supports
  263. PostgreSQL 14 and higher.
  264. Miscellaneous
  265. -------------
  266. * Adding :attr:`.EmailMultiAlternatives.alternatives` is now only supported via
  267. the :meth:`~.EmailMultiAlternatives.attach_alternative` method.
  268. * The minimum supported version of ``gettext`` is increased from 0.15 to 0.19.
  269. * ``HttpRequest.accepted_types`` is now sorted by the client's preference, based
  270. on the request's ``Accept`` header.
  271. * :attr:`.UniqueConstraint.violation_error_code` and
  272. :attr:`.UniqueConstraint.violation_error_message` are now always used when
  273. provided. Previously, these were ignored when :attr:`.UniqueConstraint.fields`
  274. were set without a :attr:`.UniqueConstraint.condition`.
  275. * The :func:`~django.template.context_processors.debug` context processor is no
  276. longer included in the default project template.
  277. * The following methods now have ``alters_data=True`` set to prevent side
  278. effects when :ref:`rendering a template context <alters-data-description>`:
  279. * :meth:`.UserManager.create_user`
  280. * :meth:`.UserManager.acreate_user`
  281. * :meth:`.UserManager.create_superuser`
  282. * :meth:`.UserManager.acreate_superuser`
  283. * :meth:`.QuerySet.create`
  284. * :meth:`.QuerySet.acreate`
  285. * :meth:`.QuerySet.bulk_create`
  286. * :meth:`.QuerySet.abulk_create`
  287. * :meth:`.QuerySet.get_or_create`
  288. * :meth:`.QuerySet.aget_or_create`
  289. * :meth:`.QuerySet.update_or_create`
  290. * :meth:`.QuerySet.aupdate_or_create`
  291. .. _deprecated-features-5.2:
  292. Features deprecated in 5.2
  293. ==========================
  294. Miscellaneous
  295. -------------
  296. * The ``all`` argument for the ``django.contrib.staticfiles.finders.find()``
  297. function is deprecated in favor of the ``find_all`` argument.