5.2.txt 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  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. * Oracle backends now support :ref:`connection pools <oracle-pool>`, by setting
  142. ``"pool"`` in the :setting:`OPTIONS` part of your database configuration.
  143. Decorators
  144. ~~~~~~~~~~
  145. * :func:`~django.utils.decorators.method_decorator` now supports wrapping
  146. asynchronous view methods.
  147. Email
  148. ~~~~~
  149. * Tuple items of :class:`EmailMessage.attachments
  150. <django.core.mail.EmailMessage>` and
  151. :class:`EmailMultiAlternatives.attachments
  152. <django.core.mail.EmailMultiAlternatives>` are now named tuples, as opposed
  153. to regular tuples.
  154. * :attr:`EmailMultiAlternatives.alternatives
  155. <django.core.mail.EmailMultiAlternatives.alternatives>` is now a list of
  156. named tuples, as opposed to regular tuples.
  157. * The new :meth:`~django.core.mail.EmailMultiAlternatives.body_contains` method
  158. returns a boolean indicating whether a provided text is contained in the
  159. email ``body`` and in all attached MIME type ``text/*`` alternatives.
  160. Error Reporting
  161. ~~~~~~~~~~~~~~~
  162. * The attribute :attr:`.SafeExceptionReporterFilter.hidden_settings` now
  163. treats values as sensitive if their name includes ``AUTH``.
  164. File Storage
  165. ~~~~~~~~~~~~
  166. * ...
  167. File Uploads
  168. ~~~~~~~~~~~~
  169. * ...
  170. Forms
  171. ~~~~~
  172. * The new :class:`~django.forms.ColorInput` form widget is for entering a color
  173. in ``rrggbb`` hexadecimal format and renders as ``<input type="color" ...>``.
  174. Some browsers support a visual color picker interface for this input type.
  175. * The new :class:`~django.forms.SearchInput` form widget is for entering search
  176. queries and renders as ``<input type="search" ...>``.
  177. * The new :class:`~django.forms.TelInput` form widget is for entering telephone
  178. numbers and renders as ``<input type="tel" ...>``.
  179. * The new ``field_id`` argument for :class:`~django.forms.ErrorList` allows an
  180. HTML ``id`` attribute to be added in the error template. See
  181. :attr:`.ErrorList.field_id` for details.
  182. * An :attr:`~django.forms.BoundField.aria_describedby` property is added to
  183. ``BoundField`` to ease use of this HTML attribute in templates.
  184. * To improve accessibility for screen reader users ``aria-describedby`` is used
  185. to associated form fields with their error messages. See
  186. :ref:`how form errors are displayed <form-error-display>` for details.
  187. * The new asset object :class:`~django.forms.Script` is available for adding
  188. custom HTML-attributes to JavaScript in form media. See
  189. :ref:`paths as objects <form-media-asset-objects>` for more details.
  190. Generic Views
  191. ~~~~~~~~~~~~~
  192. * ...
  193. Internationalization
  194. ~~~~~~~~~~~~~~~~~~~~
  195. * ...
  196. Logging
  197. ~~~~~~~
  198. * ...
  199. Management Commands
  200. ~~~~~~~~~~~~~~~~~~~
  201. * A new warning is displayed when running :djadmin:`runserver`, indicating that
  202. it is unsuitable for production. This warning can be suppressed by setting
  203. the :envvar:`HIDE_PRODUCTION_WARNING` environment variable to ``"true"``.
  204. * The :djadmin:`makemigrations` and :djadmin:`migrate` commands have a new
  205. ``Command.autodetector`` attribute for subclasses to override in order to use
  206. a custom autodetector class.
  207. * The new :meth:`.BaseCommand.get_check_kwargs` method can be overridden in
  208. custom commands to control the running of system checks, e.g. to opt into
  209. database-dependent checks.
  210. Migrations
  211. ~~~~~~~~~~
  212. * The new operation :class:`.AlterConstraint` is a no-op operation that alters
  213. constraints without dropping and recreating constraints in the database.
  214. Models
  215. ~~~~~~
  216. * The ``SELECT`` clause generated when using :meth:`.QuerySet.values` and
  217. :meth:`.QuerySet.values_list` now matches the specified order of the
  218. referenced expressions. Previously, the order was based of a set of
  219. counterintuitive rules which made query combination through methods such as
  220. :meth:`.QuerySet.union` unpredictable.
  221. * Added support for validation of model constraints which use a
  222. :class:`~django.db.models.GeneratedField`.
  223. * The new :attr:`.Expression.set_returning` attribute specifies that the
  224. expression contains a set-returning function, enforcing subquery evaluation.
  225. This is necessary for many Postgres set-returning functions.
  226. * :attr:`CharField.max_length <django.db.models.CharField.max_length>` is no
  227. longer required to be set on SQLite, which supports unlimited ``VARCHAR``
  228. columns.
  229. * :meth:`.QuerySet.explain` now supports the ``memory`` and ``serialize``
  230. options on PostgreSQL 17+.
  231. Requests and Responses
  232. ~~~~~~~~~~~~~~~~~~~~~~
  233. * The new :attr:`.HttpResponse.text` property provides the string
  234. representation of :attr:`.HttpResponse.content`.
  235. * The new :meth:`.HttpRequest.get_preferred_type` method can be used to query
  236. the preferred media type the client accepts.
  237. * The new ``preserve_request`` argument for
  238. :class:`~django.http.HttpResponseRedirect` and
  239. :class:`~django.http.HttpResponsePermanentRedirect`
  240. determines whether the HTTP status codes 302/307 or 301/308 are used,
  241. respectively.
  242. * The new ``preserve_request`` argument for
  243. :func:`~django.shortcuts.redirect` allows to instruct the user agent to reuse
  244. the HTTP method and body during redirection using specific status codes.
  245. Security
  246. ~~~~~~~~
  247. * ...
  248. Serialization
  249. ~~~~~~~~~~~~~
  250. * Each serialization format now defines a ``Deserializer`` class, rather than a
  251. function, to improve extensibility when defining a
  252. :ref:`custom serialization format <custom-serialization-formats>`.
  253. Signals
  254. ~~~~~~~
  255. * ...
  256. Templates
  257. ~~~~~~~~~
  258. * The new :meth:`~django.template.Library.simple_block_tag` decorator enables
  259. the creation of simple block tags, which can accept and use a section of the
  260. template.
  261. Tests
  262. ~~~~~
  263. * Stack frames from Django's custom assertions are now hidden. This makes test
  264. failures easier to read and enables :option:`test --pdb` to directly enter
  265. into the failing test method.
  266. * Data loaded from :attr:`~django.test.TransactionTestCase.fixtures` and from
  267. migrations enabled with :ref:`serialized_rollback=True
  268. <test-case-serialized-rollback>` are now available during
  269. ``TransactionTestCase.setUpClass()``.
  270. URLs
  271. ~~~~
  272. * :func:`~django.urls.reverse` now accepts ``query`` and ``fragment`` keyword
  273. arguments, allowing the addition of a query string and/or fragment identifier
  274. in the generated URL, respectively.
  275. Utilities
  276. ~~~~~~~~~
  277. * :class:`~django.utils.safestring.SafeString` now returns
  278. :py:data:`NotImplemented` in ``__add__`` for non-string right-hand side
  279. values. This aligns with the :py:class:`str` addition behavior and allows
  280. ``__radd__`` to be used if available.
  281. * :func:`~django.utils.html.format_html_join` now supports taking an iterable
  282. of mappings, passing their contents as keyword arguments to
  283. :func:`~django.utils.html.format_html`.
  284. Validators
  285. ~~~~~~~~~~
  286. * ...
  287. .. _backwards-incompatible-5.2:
  288. Backwards incompatible changes in 5.2
  289. =====================================
  290. Database backend API
  291. --------------------
  292. This section describes changes that may be needed in third-party database
  293. backends.
  294. * The new :meth:`Model._is_pk_set() <django.db.models.Model._is_pk_set>` method
  295. allows checking if a Model instance's primary key is defined.
  296. * ``BaseDatabaseOperations.adapt_decimalfield_value()`` is now a no-op, simply
  297. returning the given value.
  298. :mod:`django.contrib.gis`
  299. -------------------------
  300. * Support for PostGIS 3.0 is removed.
  301. * Support for GDAL 3.0 is removed.
  302. Dropped support for PostgreSQL 13
  303. ---------------------------------
  304. Upstream support for PostgreSQL 13 ends in November 2025. Django 5.2 supports
  305. PostgreSQL 14 and higher.
  306. Changed MySQL connection character set default
  307. ----------------------------------------------
  308. MySQL connections now default to using the ``utf8mb4`` character set, instead
  309. of ``utf8``, which is an alias for the deprecated character set ``utf8mb3``.
  310. ``utf8mb3`` can be specified in the ``OPTIONS`` part of the ``DATABASES``
  311. setting, if needed for legacy databases.
  312. Miscellaneous
  313. -------------
  314. * Adding :attr:`.EmailMultiAlternatives.alternatives` is now only supported via
  315. the :meth:`~.EmailMultiAlternatives.attach_alternative` method.
  316. * The minimum supported version of ``gettext`` is increased from 0.15 to 0.19.
  317. * ``HttpRequest.accepted_types`` is now sorted by the client's preference,
  318. based on the request's ``Accept`` header.
  319. * The attributes :attr:`.UniqueConstraint.violation_error_code` and
  320. :attr:`.UniqueConstraint.violation_error_message` are now always used when
  321. provided. Previously, they were ignored if :attr:`.UniqueConstraint.fields`
  322. was set without a :attr:`.UniqueConstraint.condition`.
  323. * The :func:`~django.template.context_processors.debug` context processor is no
  324. longer included in the default project template.
  325. * The following methods now have ``alters_data=True`` set to prevent side
  326. effects when :ref:`rendering a template context <alters-data-description>`:
  327. * :meth:`.UserManager.create_user`
  328. * :meth:`.UserManager.acreate_user`
  329. * :meth:`.UserManager.create_superuser`
  330. * :meth:`.UserManager.acreate_superuser`
  331. * :meth:`.QuerySet.create`
  332. * :meth:`.QuerySet.acreate`
  333. * :meth:`.QuerySet.bulk_create`
  334. * :meth:`.QuerySet.abulk_create`
  335. * :meth:`.QuerySet.get_or_create`
  336. * :meth:`.QuerySet.aget_or_create`
  337. * :meth:`.QuerySet.update_or_create`
  338. * :meth:`.QuerySet.aupdate_or_create`
  339. * The minimum supported version of ``oracledb`` is increased from 1.3.2 to
  340. 2.3.0.
  341. .. _deprecated-features-5.2:
  342. Features deprecated in 5.2
  343. ==========================
  344. Miscellaneous
  345. -------------
  346. * The ``all`` argument for the ``django.contrib.staticfiles.finders.find()``
  347. function is deprecated in favor of the ``find_all`` argument.
  348. * The fallback to ``request.user`` when ``user`` is ``None`` in
  349. ``django.contrib.auth.login()`` and ``django.contrib.auth.alogin()`` will be
  350. removed.
  351. * The ``ordering`` keyword argument of the PostgreSQL specific aggregation
  352. functions ``django.contrib.postgres.aggregates.ArrayAgg``,
  353. ``django.contrib.postgres.aggregates.JSONBAgg``, and
  354. ``django.contrib.postgres.aggregates.StringAgg`` is deprecated in favor
  355. of the ``order_by`` argument.