4.2.txt 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  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. * :class:`~django.contrib.auth.forms.UserCreationForm` now saves many-to-many
  48. form fields for a custom user model.
  49. :mod:`django.contrib.contenttypes`
  50. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  51. * ...
  52. :mod:`django.contrib.gis`
  53. ~~~~~~~~~~~~~~~~~~~~~~~~~
  54. * The :doc:`GeoJSON serializer </ref/contrib/gis/serializers>` now outputs the
  55. ``id`` key for serialized features, which defaults to the primary key of
  56. objects.
  57. * The :class:`~django.contrib.gis.gdal.GDALRaster` class now supports
  58. :class:`pathlib.Path`.
  59. * The :class:`~django.contrib.gis.geoip2.GeoIP2` class now supports ``.mmdb``
  60. files downloaded from DB-IP.
  61. * The OpenLayers template widget no longer includes inline CSS (which also
  62. removes the former ``map_css`` block) to better comply with a strict Content
  63. Security Policy.
  64. :mod:`django.contrib.messages`
  65. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  66. * ...
  67. :mod:`django.contrib.postgres`
  68. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  69. * The new :lookup:`trigram_strict_word_similar` lookup, and the
  70. :class:`TrigramStrictWordSimilarity()
  71. <django.contrib.postgres.search.TrigramStrictWordSimilarity>` and
  72. :class:`TrigramStrictWordDistance()
  73. <django.contrib.postgres.search.TrigramStrictWordDistance>` expressions allow
  74. using trigram strict word similarity.
  75. * The :lookup:`arrayfield.overlap` lookup now supports ``QuerySet.values()``
  76. and ``values_list()`` as a right-hand side.
  77. :mod:`django.contrib.redirects`
  78. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  79. * ...
  80. :mod:`django.contrib.sessions`
  81. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  82. * ...
  83. :mod:`django.contrib.sitemaps`
  84. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  85. * ...
  86. :mod:`django.contrib.sites`
  87. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  88. * ...
  89. :mod:`django.contrib.staticfiles`
  90. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  91. * :class:`~django.contrib.staticfiles.storage.ManifestStaticFilesStorage` now
  92. replaces paths to JavaScript modules in ``import`` and ``export`` statements
  93. with their hashed counterparts.
  94. :mod:`django.contrib.syndication`
  95. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  96. * ...
  97. Cache
  98. ~~~~~
  99. * ...
  100. CSRF
  101. ~~~~
  102. * ...
  103. Decorators
  104. ~~~~~~~~~~
  105. * ...
  106. Email
  107. ~~~~~
  108. * ...
  109. Error Reporting
  110. ~~~~~~~~~~~~~~~
  111. * The debug page now shows :pep:`exception notes <678>` and
  112. :pep:`fine-grained error locations <657>` on Python 3.11+.
  113. File Storage
  114. ~~~~~~~~~~~~
  115. * ...
  116. File Uploads
  117. ~~~~~~~~~~~~
  118. * ...
  119. Forms
  120. ~~~~~
  121. * :class:`~django.forms.ModelForm` now accepts the new ``Meta`` option
  122. ``formfield_callback`` to customize form fields.
  123. * :func:`~django.forms.models.modelform_factory` now respects the
  124. ``formfield_callback`` attribute of the ``form``’s ``Meta``.
  125. * Session cookies are now treated as credentials and therefore hidden and
  126. replaced with stars (``**********``) in error reports.
  127. Generic Views
  128. ~~~~~~~~~~~~~
  129. * ...
  130. Internationalization
  131. ~~~~~~~~~~~~~~~~~~~~
  132. * Added support and translations for the Central Kurdish (Sorani) language.
  133. * The :class:`~django.middleware.locale.LocaleMiddleware` now respects a
  134. language from the request when :func:`~django.conf.urls.i18n.i18n_patterns`
  135. is used with the ``prefix_default_language`` argument set to ``False``.
  136. Logging
  137. ~~~~~~~
  138. * The :ref:`django-db-logger` logger now logs transaction management queries
  139. (``BEGIN``, ``COMMIT``, and ``ROLLBACK``) at the ``DEBUG`` level.
  140. Management Commands
  141. ~~~~~~~~~~~~~~~~~~~
  142. * :djadmin:`makemessages` command now supports locales with private sub-tags
  143. such as ``nl_NL-x-informal``.
  144. * The new :option:`makemigrations --update` option merges model changes into
  145. the latest migration and optimizes the resulting operations.
  146. Migrations
  147. ~~~~~~~~~~
  148. * Migrations now support serialization of ``enum.Flag`` objects.
  149. Models
  150. ~~~~~~
  151. * ``QuerySet`` now extensively supports filtering against
  152. :ref:`window-functions` with the exception of disjunctive filter lookups
  153. against window functions when performing aggregation.
  154. * :meth:`~.QuerySet.prefetch_related` now supports
  155. :class:`~django.db.models.Prefetch` objects with sliced querysets.
  156. * :ref:`Registering lookups <lookup-registration-api>` on
  157. :class:`~django.db.models.Field` instances is now supported.
  158. * The new ``robust`` argument for :func:`~django.db.transaction.on_commit`
  159. allows performing actions that can fail after a database transaction is
  160. successfully committed.
  161. * The new :class:`KT() <django.db.models.fields.json.KT>` expression represents
  162. the text value of a key, index, or path transform of
  163. :class:`~django.db.models.JSONField`.
  164. * :class:`~django.db.models.functions.Now` now supports microsecond precision
  165. on MySQL and millisecond precision on SQLite.
  166. * :class:`F() <django.db.models.F>` expressions that output ``BooleanField``
  167. can now be negated using ``~F()`` (inversion operator).
  168. * ``Model`` now provides asynchronous versions of some methods that use the
  169. database, using an ``a`` prefix: :meth:`~.Model.adelete`,
  170. :meth:`~.Model.arefresh_from_db`, and :meth:`~.Model.asave`.
  171. * Related managers now provide asynchronous versions of methods that change a
  172. set of related objects, using an ``a`` prefix: :meth:`~.RelatedManager.aadd`,
  173. :meth:`~.RelatedManager.aclear`, :meth:`~.RelatedManager.aremove`, and
  174. :meth:`~.RelatedManager.aset`.
  175. Requests and Responses
  176. ~~~~~~~~~~~~~~~~~~~~~~
  177. * ...
  178. Security
  179. ~~~~~~~~
  180. * ...
  181. Serialization
  182. ~~~~~~~~~~~~~
  183. * ...
  184. Signals
  185. ~~~~~~~
  186. * ...
  187. Templates
  188. ~~~~~~~~~
  189. * ...
  190. Tests
  191. ~~~~~
  192. * The :option:`test --debug-sql` option now formats SQL queries with
  193. ``sqlparse``.
  194. * The :class:`~django.test.RequestFactory`,
  195. :class:`~django.test.AsyncRequestFactory`, :class:`~django.test.Client`, and
  196. :class:`~django.test.AsyncClient` classes now support the ``headers``
  197. parameter, which accepts a dictionary of header names and values. This allows
  198. a more natural syntax for declaring headers.
  199. .. code-block:: python
  200. # Before:
  201. self.client.get("/home/", HTTP_ACCEPT_LANGUAGE="fr")
  202. await self.async_client.get("/home/", ACCEPT_LANGUAGE="fr")
  203. # After:
  204. self.client.get("/home/", headers={"accept-language": "fr"})
  205. await self.async_client.get("/home/", headers={"accept-language": "fr"})
  206. URLs
  207. ~~~~
  208. * ...
  209. Utilities
  210. ~~~~~~~~~
  211. * The new ``encoder`` parameter for :meth:`django.utils.html.json_script`
  212. function allows customizing a JSON encoder class.
  213. * The private internal vendored copy of ``urllib.parse.urlsplit()`` now strips
  214. ``'\r'``, ``'\n'``, and ``'\t'`` (see :cve:`2022-0391` and :bpo:`43882`).
  215. This is to protect projects that may be incorrectly using the internal
  216. ``url_has_allowed_host_and_scheme()`` function, instead of using one of the
  217. documented functions for handling URL redirects. The Django functions were
  218. not affected.
  219. * The new :func:`django.utils.http.content_disposition_header` function returns
  220. a ``Content-Disposition`` HTTP header value as specified by :rfc:`6266`.
  221. Validators
  222. ~~~~~~~~~~
  223. * The list of common passwords used by ``CommonPasswordValidator`` is updated
  224. to the most recent version.
  225. .. _backwards-incompatible-4.2:
  226. Backwards incompatible changes in 4.2
  227. =====================================
  228. Database backend API
  229. --------------------
  230. This section describes changes that may be needed in third-party database
  231. backends.
  232. * ``DatabaseFeatures.allows_group_by_pk`` is removed as it only remained to
  233. accommodate a MySQL extension that has been supplanted by proper functional
  234. dependency detection in MySQL 5.7.15. Note that
  235. ``DatabaseFeatures.allows_group_by_selected_pks`` is still supported and
  236. should be enabled if your backend supports functional dependency detection in
  237. ``GROUP BY`` clauses as specified by the ``SQL:1999`` standard.
  238. Dropped support for MariaDB 10.3
  239. --------------------------------
  240. Upstream support for MariaDB 10.3 ends in May 2023. Django 4.2 supports MariaDB
  241. 10.4 and higher.
  242. Dropped support for MySQL 5.7
  243. -----------------------------
  244. Upstream support for MySQL 5.7 ends in October 2023. Django 4.2 supports MySQL
  245. 8 and higher.
  246. Dropped support for PostgreSQL 11
  247. ---------------------------------
  248. Upstream support for PostgreSQL 11 ends in November 2023. Django 4.2 supports
  249. PostgreSQL 12 and higher.
  250. Setting ``update_fields`` in ``Model.save()`` may now be required
  251. -----------------------------------------------------------------
  252. In order to avoid updating unnecessary columns,
  253. :meth:`.QuerySet.update_or_create` now passes ``update_fields`` to the
  254. :meth:`Model.save() <django.db.models.Model.save>` calls. As a consequence, any
  255. fields modified in the custom ``save()`` methods should be added to the
  256. ``update_fields`` keyword argument before calling ``super()``. See
  257. :ref:`overriding-model-methods` for more details.
  258. Miscellaneous
  259. -------------
  260. * The undocumented ``SimpleTemplateResponse.rendering_attrs`` and
  261. ``TemplateResponse.rendering_attrs`` are renamed to ``non_picklable_attrs``.
  262. * The undocumented ``django.http.multipartparser.parse_header()`` function is
  263. removed. Use ``django.utils.http.parse_header_parameters()`` instead.
  264. * :ttag:`{% blocktranslate asvar … %}<blocktranslate>` result is now marked as
  265. safe for (HTML) output purposes.
  266. * The ``autofocus`` HTML attribute in the admin search box is removed as it can
  267. be confusing for screen readers.
  268. * The :option:`makemigrations --check` option no longer creates missing
  269. migration files.
  270. * The ``alias`` argument for :meth:`.Expression.get_group_by_cols` is removed.
  271. * The minimum supported version of ``sqlparse`` is increased from 0.2.2 to
  272. 0.2.3.
  273. * The undocumented ``negated`` parameter of the
  274. :class:`~django.db.models.Exists` expression is removed.
  275. * The ``is_summary`` argument of the undocumented ``Query.add_annotation()``
  276. method is removed.
  277. * The minimum supported version of SQLite is increased from 3.9.0 to 3.21.0.
  278. * :djadmin:`inspectdb` now uses ``display_size`` from
  279. ``DatabaseIntrospection.get_table_description()`` rather than
  280. ``internal_size`` for ``CharField``.
  281. .. _deprecated-features-4.2:
  282. Features deprecated in 4.2
  283. ==========================
  284. ``index_together`` option is deprecated in favor of ``indexes``
  285. ---------------------------------------------------------------
  286. The :attr:`Meta.index_together <django.db.models.Options.index_together>`
  287. option is deprecated in favor of the :attr:`~django.db.models.Options.indexes`
  288. option.
  289. Migrating existing ``index_together`` should be handled as a migration. For
  290. example::
  291. class Author(models.Model):
  292. rank = models.IntegerField()
  293. name = models.CharField(max_length=30)
  294. class Meta:
  295. index_together = [["rank", "name"]]
  296. Should become::
  297. class Author(models.Model):
  298. rank = models.IntegerField()
  299. name = models.CharField(max_length=30)
  300. class Meta:
  301. indexes = [models.Index(fields=["rank", "name"])]
  302. Running the :djadmin:`makemigrations` command will generate a migration
  303. containing a :class:`~django.db.migrations.operations.RenameIndex` operation
  304. which will rename the existing index.
  305. The ``AlterIndexTogether`` migration operation is now officially supported only
  306. for pre-Django 4.2 migration files. For backward compatibility reasons, it's
  307. still part of the public API, and there's no plan to deprecate or remove it,
  308. but it should not be used for new migrations. Use
  309. :class:`~django.db.migrations.operations.AddIndex` and
  310. :class:`~django.db.migrations.operations.RemoveIndex` operations instead.
  311. Passing encoded JSON string literals to ``JSONField`` is deprecated
  312. -------------------------------------------------------------------
  313. ``JSONField`` and its associated lookups and aggregates use to allow passing
  314. JSON encoded string literals which caused ambiguity on whether string literals
  315. were already encoded from database backend's perspective.
  316. During the deprecation period string literals will be attempted to be JSON
  317. decoded and a warning will be emitted on success that points at passing
  318. non-encoded forms instead.
  319. Code that use to pass JSON encoded string literals::
  320. Document.objects.bulk_create(
  321. Document(data=Value("null")),
  322. Document(data=Value("[]")),
  323. Document(data=Value('"foo-bar"')),
  324. )
  325. Document.objects.annotate(
  326. JSONBAgg("field", default=Value('[]')),
  327. )
  328. Should become::
  329. Document.objects.bulk_create(
  330. Document(data=Value(None, JSONField())),
  331. Document(data=[]),
  332. Document(data="foo-bar"),
  333. )
  334. Document.objects.annotate(
  335. JSONBAgg("field", default=[]),
  336. )
  337. From Django 5.1+ string literals will be implicitly interpreted as JSON string
  338. literals.
  339. Miscellaneous
  340. -------------
  341. * The ``BaseUserManager.make_random_password()`` method is deprecated. See
  342. `recipes and best practices
  343. <https://docs.python.org/3/library/secrets.html#recipes-and-best-practices>`_
  344. for using Python's :py:mod:`secrets` module to generate passwords.
  345. * The ``length_is`` template filter is deprecated in favor of :tfilter:`length`
  346. and the ``==`` operator within an :ttag:`{% if %}<if>` tag. For example
  347. .. code-block:: html+django
  348. {% if value|length == 4 %}…{% endif %}
  349. {% if value|length == 4 %}True{% else %}False{% endif %}
  350. instead of:
  351. .. code-block:: html+django
  352. {% if value|length_is:4 %}…{% endif %}
  353. {{ value|length_is:4 }}
  354. * ``django.contrib.auth.hashers.SHA1PasswordHasher``,
  355. ``django.contrib.auth.hashers.UnsaltedSHA1PasswordHasher``, and
  356. ``django.contrib.auth.hashers.UnsaltedMD5PasswordHasher`` are deprecated.
  357. * ``django.contrib.postgres.fields.CICharField`` is deprecated in favor of
  358. ``CharField(db_collation="…")`` with a case-insensitive non-deterministic
  359. collation.
  360. * ``django.contrib.postgres.fields.CIEmailField`` is deprecated in favor of
  361. ``EmailField(db_collation="…")`` with a case-insensitive non-deterministic
  362. collation.
  363. * ``django.contrib.postgres.fields.CITextField`` is deprecated in favor of
  364. ``TextField(db_collation="…")`` with a case-insensitive non-deterministic
  365. collation.
  366. * ``django.contrib.postgres.fields.CIText`` mixin is deprecated.
  367. * The ``map_height`` and ``map_width`` attributes of ``BaseGeometryWidget`` are
  368. deprecated, use CSS to size map widgets instead.
  369. * ``SimpleTestCase.assertFormsetError()`` is deprecated in favor of
  370. ``assertFormSetError()``.
  371. * ``TransactionTestCase.assertQuerysetEqual()`` is deprecated in favor of
  372. ``assertQuerySetEqual()``.
  373. * Passing positional arguments to ``Signer`` and ``TimestampSigner`` is
  374. deprecated in favor of keyword-only arguments.