4.2.txt 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. ============================================
  2. Django 4.2 release notes - UNDER DEVELOPMENT
  3. ============================================
  4. *Expected April 2023*
  5. Welcome to Django 4.2!
  6. These release notes cover the :ref:`new features <whats-new-4.2>`, as well as
  7. some :ref:`backwards incompatible changes <backwards-incompatible-4.2>` you'll
  8. want to be aware of when upgrading from Django 4.1 or earlier. We've
  9. :ref:`begun the deprecation process for some features
  10. <deprecated-features-4.2>`.
  11. See the :doc:`/howto/upgrade-version` guide if you're updating an existing
  12. project.
  13. Python compatibility
  14. ====================
  15. Django 4.2 supports Python 3.8, 3.9, 3.10, and 3.11. We **highly recommend**
  16. and only officially support the latest release of each series.
  17. .. _whats-new-4.2:
  18. What's new in Django 4.2
  19. ========================
  20. Minor features
  21. --------------
  22. :mod:`django.contrib.admin`
  23. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  24. * The light or dark color theme of the admin can now be toggled in the UI, as
  25. well as being set to follow the system setting.
  26. * The admin's font stack now prefers system UI fonts and no longer requires
  27. downloading fonts. Additionally, CSS variables are available to more easily
  28. override the default font families.
  29. * The :source:`admin/delete_confirmation.html
  30. <django/contrib/admin/templates/admin/delete_confirmation.html>` template now
  31. has some additional blocks and scripting hooks to ease customization.
  32. * The chosen options of
  33. :attr:`~django.contrib.admin.ModelAdmin.filter_horizontal` and
  34. :attr:`~django.contrib.admin.ModelAdmin.filter_vertical` widgets are now
  35. filterable.
  36. * The ``admin/base.html`` template now has a new block ``nav-breadcrumbs``
  37. which contains the navigation landmark and the ``breadcrumbs`` block.
  38. * :attr:`.ModelAdmin.list_editable` now uses atomic transactions when making
  39. edits.
  40. :mod:`django.contrib.admindocs`
  41. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  42. * ...
  43. :mod:`django.contrib.auth`
  44. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  45. * The default iteration count for the PBKDF2 password hasher is increased from
  46. 390,000 to 480,000.
  47. :mod:`django.contrib.contenttypes`
  48. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  49. * ...
  50. :mod:`django.contrib.gis`
  51. ~~~~~~~~~~~~~~~~~~~~~~~~~
  52. * The :doc:`GeoJSON serializer </ref/contrib/gis/serializers>` now outputs the
  53. ``id`` key for serialized features, which defaults to the primary key of
  54. objects.
  55. * The :class:`~django.contrib.gis.gdal.GDALRaster` class now supports
  56. :class:`pathlib.Path`.
  57. * The :class:`~django.contrib.gis.geoip2.GeoIP2` class now supports ``.mmdb``
  58. files downloaded from DB-IP.
  59. * The OpenLayers template widget no longer includes inline CSS (which also
  60. removes the former ``map_css`` block) to better comply with a strict Content
  61. Security Policy.
  62. :mod:`django.contrib.messages`
  63. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  64. * ...
  65. :mod:`django.contrib.postgres`
  66. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  67. * The new :lookup:`trigram_strict_word_similar` lookup, and the
  68. :class:`TrigramStrictWordSimilarity()
  69. <django.contrib.postgres.search.TrigramStrictWordSimilarity>` and
  70. :class:`TrigramStrictWordDistance()
  71. <django.contrib.postgres.search.TrigramStrictWordDistance>` expressions allow
  72. using trigram strict word similarity.
  73. :mod:`django.contrib.redirects`
  74. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  75. * ...
  76. :mod:`django.contrib.sessions`
  77. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  78. * ...
  79. :mod:`django.contrib.sitemaps`
  80. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  81. * ...
  82. :mod:`django.contrib.sites`
  83. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  84. * ...
  85. :mod:`django.contrib.staticfiles`
  86. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  87. * ...
  88. :mod:`django.contrib.syndication`
  89. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  90. * ...
  91. Cache
  92. ~~~~~
  93. * ...
  94. CSRF
  95. ~~~~
  96. * ...
  97. Decorators
  98. ~~~~~~~~~~
  99. * ...
  100. Email
  101. ~~~~~
  102. * ...
  103. Error Reporting
  104. ~~~~~~~~~~~~~~~
  105. * ...
  106. File Storage
  107. ~~~~~~~~~~~~
  108. * ...
  109. File Uploads
  110. ~~~~~~~~~~~~
  111. * ...
  112. Forms
  113. ~~~~~
  114. * :class:`~django.forms.ModelForm` now accepts the new ``Meta`` option
  115. ``formfield_callback`` to customize form fields.
  116. * :func:`~django.forms.models.modelform_factory` now respects the
  117. ``formfield_callback`` attribute of the ``form``’s ``Meta``.
  118. * Session cookies are now treated as credentials and therefore hidden and
  119. replaced with stars (``**********``) in error reports.
  120. Generic Views
  121. ~~~~~~~~~~~~~
  122. * ...
  123. Internationalization
  124. ~~~~~~~~~~~~~~~~~~~~
  125. * Added support and translations for the Central Kurdish (Sorani) language.
  126. * The :class:`~django.middleware.locale.LocaleMiddleware` now respects a
  127. language from the request when :func:`~django.conf.urls.i18n.i18n_patterns`
  128. is used with the ``prefix_default_language`` argument set to ``False``.
  129. Logging
  130. ~~~~~~~
  131. * ...
  132. Management Commands
  133. ~~~~~~~~~~~~~~~~~~~
  134. * :djadmin:`makemessages` command now supports locales with private sub-tags
  135. such as ``nl_NL-x-informal``.
  136. * The new :option:`makemigrations --update` option merges model changes into
  137. the latest migration and optimizes the resulting operations.
  138. Migrations
  139. ~~~~~~~~~~
  140. * Migrations now support serialization of ``enum.Flag`` objects.
  141. Models
  142. ~~~~~~
  143. * ``QuerySet`` now extensively supports filtering against
  144. :ref:`window-functions` with the exception of disjunctive filter lookups
  145. against window functions when performing aggregation.
  146. * :meth:`~.QuerySet.prefetch_related` now supports
  147. :class:`~django.db.models.Prefetch` objects with sliced querysets.
  148. * :ref:`Registering lookups <lookup-registration-api>` on
  149. :class:`~django.db.models.Field` instances is now supported.
  150. * The new ``robust`` argument for :func:`~django.db.transaction.on_commit`
  151. allows performing actions that can fail after a database transaction is
  152. successfully committed.
  153. * The new :class:`KT() <django.db.models.fields.json.KT>` expression represents
  154. the text value of a key, index, or path transform of
  155. :class:`~django.db.models.JSONField`.
  156. * :class:`~django.db.models.functions.Now` now supports microsecond precision
  157. on MySQL and millisecond precision on SQLite.
  158. * :class:`F() <django.db.models.F>` expressions that output ``BooleanField``
  159. can now be negated using ``~F()`` (inversion operator).
  160. * ``Model`` now provides asynchronous versions of some methods that use the
  161. database, using an ``a`` prefix: :meth:`~.Model.adelete`,
  162. :meth:`~.Model.arefresh_from_db`, and :meth:`~.Model.asave`.
  163. * Related managers now provide asynchronous versions of methods that change a
  164. set of related objects, using an ``a`` prefix: :meth:`~.RelatedManager.aadd`,
  165. :meth:`~.RelatedManager.aclear`, :meth:`~.RelatedManager.aremove`, and
  166. :meth:`~.RelatedManager.aset`.
  167. Requests and Responses
  168. ~~~~~~~~~~~~~~~~~~~~~~
  169. * ...
  170. Security
  171. ~~~~~~~~
  172. * ...
  173. Serialization
  174. ~~~~~~~~~~~~~
  175. * ...
  176. Signals
  177. ~~~~~~~
  178. * ...
  179. Templates
  180. ~~~~~~~~~
  181. * ...
  182. Tests
  183. ~~~~~
  184. * The :option:`test --debug-sql` option now formats SQL queries with
  185. ``sqlparse``.
  186. * The :class:`~django.test.RequestFactory`,
  187. :class:`~django.test.AsyncRequestFactory`, :class:`~django.test.Client`, and
  188. :class:`~django.test.AsyncClient` classes now support the ``headers``
  189. parameter, which accepts a dictionary of header names and values. This allows
  190. a more natural syntax for declaring headers.
  191. .. code-block:: python
  192. # Before:
  193. self.client.get("/home/", HTTP_ACCEPT_LANGUAGE="fr")
  194. await self.async_client.get("/home/", ACCEPT_LANGUAGE="fr")
  195. # After:
  196. self.client.get("/home/", headers={"accept-language": "fr"})
  197. await self.async_client.get("/home/", headers={"accept-language": "fr"})
  198. URLs
  199. ~~~~
  200. * ...
  201. Utilities
  202. ~~~~~~~~~
  203. * The new ``encoder`` parameter for :meth:`django.utils.html.json_script`
  204. function allows customizing a JSON encoder class.
  205. * The private internal vendored copy of ``urllib.parse.urlsplit()`` now strips
  206. ``'\r'``, ``'\n'``, and ``'\t'`` (see :cve:`2022-0391` and :bpo:`43882`).
  207. This is to protect projects that may be incorrectly using the internal
  208. ``url_has_allowed_host_and_scheme()`` function, instead of using one of the
  209. documented functions for handling URL redirects. The Django functions were
  210. not affected.
  211. Validators
  212. ~~~~~~~~~~
  213. * The list of common passwords used by ``CommonPasswordValidator`` is updated
  214. to the most recent version.
  215. .. _backwards-incompatible-4.2:
  216. Backwards incompatible changes in 4.2
  217. =====================================
  218. Database backend API
  219. --------------------
  220. This section describes changes that may be needed in third-party database
  221. backends.
  222. * ``DatabaseFeatures.allows_group_by_pk`` is removed as it only remained to
  223. accommodate a MySQL extension that has been supplanted by proper functional
  224. dependency detection in MySQL 5.7.15. Note that
  225. ``DatabaseFeatures.allows_group_by_selected_pks`` is still supported and
  226. should be enabled if your backend supports functional dependency detection in
  227. ``GROUP BY`` clauses as specified by the ``SQL:1999`` standard.
  228. Dropped support for MariaDB 10.3
  229. --------------------------------
  230. Upstream support for MariaDB 10.3 ends in May 2023. Django 4.2 supports MariaDB
  231. 10.4 and higher.
  232. Dropped support for MySQL 5.7
  233. -----------------------------
  234. Upstream support for MySQL 5.7 ends in October 2023. Django 4.2 supports MySQL
  235. 8 and higher.
  236. Dropped support for PostgreSQL 11
  237. ---------------------------------
  238. Upstream support for PostgreSQL 11 ends in November 2023. Django 4.2 supports
  239. PostgreSQL 12 and higher.
  240. Setting ``update_fields`` in ``Model.save()`` may now be required
  241. -----------------------------------------------------------------
  242. In order to avoid updating unnecessary columns,
  243. :meth:`.QuerySet.update_or_create` now passes ``update_fields`` to the
  244. :meth:`Model.save() <django.db.models.Model.save>` calls. As a consequence, any
  245. fields modified in the custom ``save()`` methods should be added to the
  246. ``update_fields`` keyword argument before calling ``super()``. See
  247. :ref:`overriding-model-methods` for more details.
  248. Miscellaneous
  249. -------------
  250. * The undocumented ``SimpleTemplateResponse.rendering_attrs`` and
  251. ``TemplateResponse.rendering_attrs`` are renamed to ``non_picklable_attrs``.
  252. * The undocumented ``django.http.multipartparser.parse_header()`` function is
  253. removed. Use ``django.utils.http.parse_header_parameters()`` instead.
  254. * :ttag:`{% blocktranslate asvar … %}<blocktranslate>` result is now marked as
  255. safe for (HTML) output purposes.
  256. * The ``autofocus`` HTML attribute in the admin search box is removed as it can
  257. be confusing for screen readers.
  258. * The :option:`makemigrations --check` option no longer creates missing
  259. migration files.
  260. * The ``alias`` argument for :meth:`.Expression.get_group_by_cols` is removed.
  261. * The minimum supported version of ``sqlparse`` is increased from 0.2.2 to
  262. 0.2.3.
  263. * The undocumented ``negated`` parameter of the
  264. :class:`~django.db.models.Exists` expression is removed.
  265. .. _deprecated-features-4.2:
  266. Features deprecated in 4.2
  267. ==========================
  268. ``index_together`` option is deprecated in favor of ``indexes``
  269. ---------------------------------------------------------------
  270. The :attr:`Meta.index_together <django.db.models.Options.index_together>`
  271. option is deprecated in favor of the :attr:`~django.db.models.Options.indexes`
  272. option.
  273. Migrating existing ``index_together`` should be handled as a migration. For
  274. example::
  275. class Author(models.Model):
  276. rank = models.IntegerField()
  277. name = models.CharField(max_length=30)
  278. class Meta:
  279. index_together = [["rank", "name"]]
  280. Should become::
  281. class Author(models.Model):
  282. rank = models.IntegerField()
  283. name = models.CharField(max_length=30)
  284. class Meta:
  285. indexes = [models.Index(fields=["rank", "name"])]
  286. Running the :djadmin:`makemigrations` command will generate a migration
  287. containing a :class:`~django.db.migrations.operations.RenameIndex` operation
  288. which will rename the existing index.
  289. The ``AlterIndexTogether`` migration operation is now officially supported only
  290. for pre-Django 4.2 migration files. For backward compatibility reasons, it's
  291. still part of the public API, and there's no plan to deprecate or remove it,
  292. but it should not be used for new migrations. Use
  293. :class:`~django.db.migrations.operations.AddIndex` and
  294. :class:`~django.db.migrations.operations.RemoveIndex` operations instead.
  295. Miscellaneous
  296. -------------
  297. * The ``BaseUserManager.make_random_password()`` method is deprecated. See
  298. `recipes and best practices
  299. <https://docs.python.org/3/library/secrets.html#recipes-and-best-practices>`_
  300. for using Python's :py:mod:`secrets` module to generate passwords.
  301. * The ``length_is`` template filter is deprecated in favor of :tfilter:`length`
  302. and the ``==`` operator within an :ttag:`{% if %}<if>` tag. For example
  303. .. code-block:: html+django
  304. {% if value|length == 4 %}…{% endif %}
  305. {% if value|length == 4 %}True{% else %}False{% endif %}
  306. instead of:
  307. .. code-block:: html+django
  308. {% if value|length_is:4 %}…{% endif %}
  309. {{ value|length_is:4 }}
  310. * ``django.contrib.auth.hashers.SHA1PasswordHasher``,
  311. ``django.contrib.auth.hashers.UnsaltedSHA1PasswordHasher``, and
  312. ``django.contrib.auth.hashers.UnsaltedMD5PasswordHasher`` are deprecated.
  313. * ``django.contrib.postgres.fields.CICharField`` is deprecated in favor of
  314. ``CharField(db_collation="…")`` with a case-insensitive non-deterministic
  315. collation.
  316. * ``django.contrib.postgres.fields.CIEmailField`` is deprecated in favor of
  317. ``EmailField(db_collation="…")`` with a case-insensitive non-deterministic
  318. collation.
  319. * ``django.contrib.postgres.fields.CITextField`` is deprecated in favor of
  320. ``TextField(db_collation="…")`` with a case-insensitive non-deterministic
  321. collation.
  322. * ``django.contrib.postgres.fields.CIText`` mixin is deprecated.
  323. * The ``map_height`` and ``map_width`` attributes of ``BaseGeometryWidget`` are
  324. deprecated, use CSS to size map widgets instead.
  325. * ``SimpleTestCase.assertFormsetError()`` is deprecated in favor of
  326. ``assertFormSetError()``.
  327. * ``TransactionTestCase.assertQuerysetEqual()`` is deprecated in favor of
  328. ``assertQuerySetEqual()``.