4.2.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  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. :mod:`django.contrib.admindocs`
  39. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  40. * ...
  41. :mod:`django.contrib.auth`
  42. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  43. * The default iteration count for the PBKDF2 password hasher is increased from
  44. 390,000 to 480,000.
  45. :mod:`django.contrib.contenttypes`
  46. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  47. * ...
  48. :mod:`django.contrib.gis`
  49. ~~~~~~~~~~~~~~~~~~~~~~~~~
  50. * The :doc:`GeoJSON serializer </ref/contrib/gis/serializers>` now outputs the
  51. ``id`` key for serialized features, which defaults to the primary key of
  52. objects.
  53. * The :class:`~django.contrib.gis.gdal.GDALRaster` class now supports
  54. :class:`pathlib.Path`.
  55. * The :class:`~django.contrib.gis.geoip2.GeoIP2` class now supports ``.mmdb``
  56. files downloaded from DB-IP.
  57. * The OpenLayers template widget no longer includes inline CSS (which also
  58. removes the former ``map_css`` block) to better comply with a strict Content
  59. Security Policy.
  60. :mod:`django.contrib.messages`
  61. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  62. * ...
  63. :mod:`django.contrib.postgres`
  64. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  65. * The new :lookup:`trigram_strict_word_similar` lookup, and the
  66. :class:`TrigramStrictWordSimilarity()
  67. <django.contrib.postgres.search.TrigramStrictWordSimilarity>` and
  68. :class:`TrigramStrictWordDistance()
  69. <django.contrib.postgres.search.TrigramStrictWordDistance>` expressions allow
  70. using trigram strict word similarity.
  71. :mod:`django.contrib.redirects`
  72. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  73. * ...
  74. :mod:`django.contrib.sessions`
  75. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  76. * ...
  77. :mod:`django.contrib.sitemaps`
  78. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  79. * ...
  80. :mod:`django.contrib.sites`
  81. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  82. * ...
  83. :mod:`django.contrib.staticfiles`
  84. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  85. * ...
  86. :mod:`django.contrib.syndication`
  87. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  88. * ...
  89. Cache
  90. ~~~~~
  91. * ...
  92. CSRF
  93. ~~~~
  94. * ...
  95. Decorators
  96. ~~~~~~~~~~
  97. * ...
  98. Email
  99. ~~~~~
  100. * ...
  101. Error Reporting
  102. ~~~~~~~~~~~~~~~
  103. * ...
  104. File Storage
  105. ~~~~~~~~~~~~
  106. * ...
  107. File Uploads
  108. ~~~~~~~~~~~~
  109. * ...
  110. Forms
  111. ~~~~~
  112. * :class:`~django.forms.ModelForm` now accepts the new ``Meta`` option
  113. ``formfield_callback`` to customize form fields.
  114. * :func:`~django.forms.models.modelform_factory` now respects the
  115. ``formfield_callback`` attribute of the ``form``’s ``Meta``.
  116. Generic Views
  117. ~~~~~~~~~~~~~
  118. * ...
  119. Internationalization
  120. ~~~~~~~~~~~~~~~~~~~~
  121. * Added support and translations for the Central Kurdish (Sorani) language.
  122. Logging
  123. ~~~~~~~
  124. * ...
  125. Management Commands
  126. ~~~~~~~~~~~~~~~~~~~
  127. * :djadmin:`makemessages` command now supports locales with private sub-tags
  128. such as ``nl_NL-x-informal``.
  129. * The new :option:`makemigrations --update` option merges model changes into
  130. the latest migration and optimizes the resulting operations.
  131. Migrations
  132. ~~~~~~~~~~
  133. * Migrations now support serialization of ``enum.Flag`` objects.
  134. Models
  135. ~~~~~~
  136. * ``QuerySet`` now extensively supports filtering against
  137. :ref:`window-functions` with the exception of disjunctive filter lookups
  138. against window functions when performing aggregation.
  139. * :meth:`~.QuerySet.prefetch_related` now supports
  140. :class:`~django.db.models.Prefetch` objects with sliced querysets.
  141. * :ref:`Registering lookups <lookup-registration-api>` on
  142. :class:`~django.db.models.Field` instances is now supported.
  143. * The new ``robust`` argument for :func:`~django.db.transaction.on_commit`
  144. allows performing actions that can fail after a database transaction is
  145. successfully committed.
  146. * The new :class:`KT() <django.db.models.fields.json.KT>` expression represents
  147. the text value of a key, index, or path transform of
  148. :class:`~django.db.models.JSONField`.
  149. * :class:`~django.db.models.functions.Now` now supports microsecond precision
  150. on MySQL and millisecond precision on SQLite.
  151. Requests and Responses
  152. ~~~~~~~~~~~~~~~~~~~~~~
  153. * ...
  154. Security
  155. ~~~~~~~~
  156. * ...
  157. Serialization
  158. ~~~~~~~~~~~~~
  159. * ...
  160. Signals
  161. ~~~~~~~
  162. * ...
  163. Templates
  164. ~~~~~~~~~
  165. * ...
  166. Tests
  167. ~~~~~
  168. * ...
  169. URLs
  170. ~~~~
  171. * ...
  172. Utilities
  173. ~~~~~~~~~
  174. * The new ``encoder`` parameter for :meth:`django.utils.html.json_script`
  175. function allows customizing a JSON encoder class.
  176. * The private internal vendored copy of ``urllib.parse.urlsplit()`` now strips
  177. ``'\r'``, ``'\n'``, and ``'\t'`` (see :cve:`2022-0391` and :bpo:`43882`).
  178. This is to protect projects that may be incorrectly using the internal
  179. ``url_has_allowed_host_and_scheme()`` function, instead of using one of the
  180. documented functions for handling URL redirects. The Django functions were
  181. not affected.
  182. Validators
  183. ~~~~~~~~~~
  184. * The list of common passwords used by ``CommonPasswordValidator`` is updated
  185. to the most recent version.
  186. .. _backwards-incompatible-4.2:
  187. Backwards incompatible changes in 4.2
  188. =====================================
  189. Database backend API
  190. --------------------
  191. This section describes changes that may be needed in third-party database
  192. backends.
  193. * ...
  194. Dropped support for MariaDB 10.3
  195. --------------------------------
  196. Upstream support for MariaDB 10.3 ends in May 2023. Django 4.2 supports MariaDB
  197. 10.4 and higher.
  198. Dropped support for MySQL 5.7
  199. -----------------------------
  200. Upstream support for MySQL 5.7 ends in October 2023. Django 4.2 supports MySQL
  201. 8 and higher.
  202. Dropped support for PostgreSQL 11
  203. ---------------------------------
  204. Upstream support for PostgreSQL 11 ends in November 2023. Django 4.2 supports
  205. PostgreSQL 12 and higher.
  206. Miscellaneous
  207. -------------
  208. * The undocumented ``SimpleTemplateResponse.rendering_attrs`` and
  209. ``TemplateResponse.rendering_attrs`` are renamed to ``non_picklable_attrs``.
  210. * The undocumented ``django.http.multipartparser.parse_header()`` function is
  211. removed. Use ``django.utils.http.parse_header_parameters()`` instead.
  212. * :ttag:`{% blocktranslate asvar … %}<blocktranslate>` result is now marked as
  213. safe for (HTML) output purposes.
  214. * The ``autofocus`` HTML attribute in the admin search box is removed as it can
  215. be confusing for screen readers.
  216. * The :option:`makemigrations --check` option no longer creates missing
  217. migration files.
  218. * The ``alias`` argument for :meth:`.Expression.get_group_by_cols` is removed.
  219. .. _deprecated-features-4.2:
  220. Features deprecated in 4.2
  221. ==========================
  222. ``index_together`` option is deprecated in favor of ``indexes``
  223. ---------------------------------------------------------------
  224. The :attr:`Meta.index_together <django.db.models.Options.index_together>`
  225. option is deprecated in favor of the :attr:`~django.db.models.Options.indexes`
  226. option.
  227. Migrating existing ``index_together`` should be handled as a migration. For
  228. example::
  229. class Author(models.Model):
  230. rank = models.IntegerField()
  231. name = models.CharField(max_length=30)
  232. class Meta:
  233. index_together = [["rank", "name"]]
  234. Should become::
  235. class Author(models.Model):
  236. rank = models.IntegerField()
  237. name = models.CharField(max_length=30)
  238. class Meta:
  239. indexes = [models.Index(fields=["rank", "name"])]
  240. Running the :djadmin:`makemigrations` command will generate a migration
  241. containing a :class:`~django.db.migrations.operations.RenameIndex` operation
  242. which will rename the existing index.
  243. The ``AlterIndexTogether`` migration operation is now officially supported only
  244. for pre-Django 4.2 migration files. For backward compatibility reasons, it's
  245. still part of the public API, and there's no plan to deprecate or remove it,
  246. but it should not be used for new migrations. Use
  247. :class:`~django.db.migrations.operations.AddIndex` and
  248. :class:`~django.db.migrations.operations.RemoveIndex` operations instead.
  249. Miscellaneous
  250. -------------
  251. * The ``BaseUserManager.make_random_password()`` method is deprecated. See
  252. `recipes and best practices
  253. <https://docs.python.org/3/library/secrets.html#recipes-and-best-practices>`_
  254. for using Python's :py:mod:`secrets` module to generate passwords.
  255. * The ``length_is`` template filter is deprecated in favor of :tfilter:`length`
  256. and the ``==`` operator within an :ttag:`{% if %}<if>` tag. For example
  257. .. code-block:: html+django
  258. {% if value|length == 4 %}…{% endif %}
  259. {% if value|length == 4 %}True{% else %}False{% endif %}
  260. instead of:
  261. .. code-block:: html+django
  262. {% if value|length_is:4 %}…{% endif %}
  263. {{ value|length_is:4 }}
  264. * ``django.contrib.auth.hashers.SHA1PasswordHasher``,
  265. ``django.contrib.auth.hashers.UnsaltedSHA1PasswordHasher``, and
  266. ``django.contrib.auth.hashers.UnsaltedMD5PasswordHasher`` are deprecated.
  267. * ``django.contrib.postgres.fields.CICharField`` is deprecated in favor of
  268. ``CharField(db_collation="…")`` with a case-insensitive non-deterministic
  269. collation.
  270. * ``django.contrib.postgres.fields.CIEmailField`` is deprecated in favor of
  271. ``EmailField(db_collation="…")`` with a case-insensitive non-deterministic
  272. collation.
  273. * ``django.contrib.postgres.fields.CITextField`` is deprecated in favor of
  274. ``TextField(db_collation="…")`` with a case-insensitive non-deterministic
  275. collation.
  276. * ``django.contrib.postgres.fields.CIText`` mixin is deprecated.
  277. * The ``map_height`` and ``map_width`` attributes of ``BaseGeometryWidget`` are
  278. deprecated, use CSS to size map widgets instead.