2
0

5.2.txt 14 KB

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