4.1.txt 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. ============================================
  2. Django 4.1 release notes - UNDER DEVELOPMENT
  3. ============================================
  4. *Expected August 2022*
  5. Welcome to Django 4.1!
  6. These release notes cover the :ref:`new features <whats-new-4.1>`, as well as
  7. some :ref:`backwards incompatible changes <backwards-incompatible-4.1>` you'll
  8. want to be aware of when upgrading from Django 4.0 or earlier. We've
  9. :ref:`begun the deprecation process for some features
  10. <deprecated-features-4.1>`.
  11. See the :doc:`/howto/upgrade-version` guide if you're updating an existing
  12. project.
  13. Python compatibility
  14. ====================
  15. Django 4.1 supports Python 3.8, 3.9, and 3.10. We **highly recommend** and only
  16. officially support the latest release of each series.
  17. .. _whats-new-4.1:
  18. What's new in Django 4.1
  19. ========================
  20. .. _csrf-cookie-masked-usage:
  21. ``CSRF_COOKIE_MASKED`` setting
  22. ------------------------------
  23. The new :setting:`CSRF_COOKIE_MASKED` transitional setting allows specifying
  24. whether to mask the CSRF cookie.
  25. :class:`~django.middleware.csrf.CsrfViewMiddleware` no longer masks the CSRF
  26. cookie like it does the CSRF token in the DOM. If you are upgrading multiple
  27. instances of the same project to Django 4.1, you should set
  28. :setting:`CSRF_COOKIE_MASKED` to ``True`` during the transition, in
  29. order to allow compatibility with the older versions of Django. Once the
  30. transition to 4.1 is complete you can stop overriding
  31. :setting:`CSRF_COOKIE_MASKED`.
  32. This setting is deprecated as of this release and will be removed in Django
  33. 5.0.
  34. Minor features
  35. --------------
  36. :mod:`django.contrib.admin`
  37. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  38. * The admin :ref:`dark mode CSS variables <admin-theming>` are now applied in a
  39. separate stylesheet and template block.
  40. * :ref:`modeladmin-list-filters` providing custom ``FieldListFilter``
  41. subclasses can now control the query string value separator when filtering
  42. for multiple values using the ``__in`` lookup.
  43. * The admin :meth:`history view <django.contrib.admin.ModelAdmin.history_view>`
  44. is now paginated.
  45. :mod:`django.contrib.admindocs`
  46. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  47. * ...
  48. :mod:`django.contrib.auth`
  49. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  50. * The default iteration count for the PBKDF2 password hasher is increased from
  51. 320,000 to 390,000.
  52. :mod:`django.contrib.contenttypes`
  53. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  54. * ...
  55. :mod:`django.contrib.gis`
  56. ~~~~~~~~~~~~~~~~~~~~~~~~~
  57. * The new :meth:`.GEOSGeometry.make_valid()` method allows converting invalid
  58. geometries to valid ones.
  59. :mod:`django.contrib.messages`
  60. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  61. * ...
  62. :mod:`django.contrib.postgres`
  63. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  64. * The new :class:`BitXor() <django.contrib.postgres.aggregates.BitXor>`
  65. aggregate function returns an ``int`` of the bitwise ``XOR`` of all non-null
  66. input values.
  67. * :class:`~django.contrib.postgres.indexes.SpGistIndex` now supports covering
  68. indexes on PostgreSQL 14+.
  69. * :class:`~django.contrib.postgres.constraints.ExclusionConstraint` now
  70. supports covering exclusion constraints using SP-GiST indexes on PostgreSQL
  71. 14+.
  72. * The new ``default_bounds`` attribute of :attr:`DateTimeRangeField
  73. <django.contrib.postgres.fields.DateTimeRangeField.default_bounds>` and
  74. :attr:`DecimalRangeField
  75. <django.contrib.postgres.fields.DecimalRangeField.default_bounds>` allows
  76. specifying bounds for list and tuple inputs.
  77. * :class:`~django.contrib.postgres.constraints.ExclusionConstraint` now allows
  78. specifying operator classes with the
  79. :class:`OpClass() <django.contrib.postgres.indexes.OpClass>` expression.
  80. :mod:`django.contrib.redirects`
  81. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  82. * ...
  83. :mod:`django.contrib.sessions`
  84. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  85. * ...
  86. :mod:`django.contrib.sitemaps`
  87. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  88. * The default sitemap index template ``<sitemapindex>`` now includes the
  89. ``<lastmod>`` timestamp where available, through the new
  90. :meth:`~django.contrib.sitemaps.Sitemap.get_latest_lastmod` method. Custom
  91. sitemap index templates should be updated for the adjusted :ref:`context
  92. variables <sitemap-index-context-variables>`.
  93. :mod:`django.contrib.sites`
  94. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  95. * ...
  96. :mod:`django.contrib.staticfiles`
  97. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  98. * :class:`~django.contrib.staticfiles.storage.ManifestStaticFilesStorage` now
  99. replaces paths to CSS source map references with their hashed counterparts.
  100. :mod:`django.contrib.syndication`
  101. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  102. * ...
  103. Cache
  104. ~~~~~
  105. * ...
  106. CSRF
  107. ~~~~
  108. * ...
  109. Decorators
  110. ~~~~~~~~~~
  111. * ...
  112. Email
  113. ~~~~~
  114. * ...
  115. Error Reporting
  116. ~~~~~~~~~~~~~~~
  117. * ...
  118. File Storage
  119. ~~~~~~~~~~~~
  120. * ...
  121. File Uploads
  122. ~~~~~~~~~~~~
  123. * ...
  124. Forms
  125. ~~~~~
  126. * The new :meth:`~django.forms.BoundField.legend_tag` allows rendering field
  127. labels in ``<legend>`` tags via the new ``tag`` argument of
  128. :meth:`~django.forms.BoundField.label_tag`.
  129. Generic Views
  130. ~~~~~~~~~~~~~
  131. * ...
  132. Internationalization
  133. ~~~~~~~~~~~~~~~~~~~~
  134. * The :func:`~django.conf.urls.i18n.i18n_patterns` function now supports
  135. languages with both scripts and regions.
  136. Logging
  137. ~~~~~~~
  138. * ...
  139. Management Commands
  140. ~~~~~~~~~~~~~~~~~~~
  141. * :option:`makemigrations --no-input` now logs default answers and reasons why
  142. migrations cannot be created.
  143. * The new :option:`makemigrations --scriptable` options diverts log output and
  144. input prompts to ``stderr``, writing only paths of generated migration files
  145. to ``stdout``.
  146. Migrations
  147. ~~~~~~~~~~
  148. * ...
  149. Models
  150. ~~~~~~
  151. * The ``order_by`` argument of the
  152. :class:`~django.db.models.expressions.Window` expression now accepts string
  153. references to fields and transforms.
  154. * The new :setting:`CONN_HEALTH_CHECKS` setting allows enabling health checks
  155. for :ref:`persistent database connections <persistent-database-connections>`
  156. in order to reduce the number of failed requests, e.g. after database server
  157. restart.
  158. * :meth:`.QuerySet.bulk_create` now supports updating fields when a row
  159. insertion fails uniqueness constraints. This is supported on MariaDB, MySQL,
  160. PostgreSQL, and SQLite 3.24+.
  161. Requests and Responses
  162. ~~~~~~~~~~~~~~~~~~~~~~
  163. * ...
  164. Security
  165. ~~~~~~~~
  166. * ...
  167. Serialization
  168. ~~~~~~~~~~~~~
  169. * ...
  170. Signals
  171. ~~~~~~~
  172. * The :data:`~django.db.models.signals.pre_delete` and
  173. :data:`~django.db.models.signals.post_delete` signals now dispatch the
  174. ``origin`` of the deletion.
  175. Templates
  176. ~~~~~~~~~
  177. * :tfilter:`json_script` template filter now allows wrapping in a ``<script>``
  178. tag without the HTML ``id`` attribute.
  179. Tests
  180. ~~~~~
  181. * A nested atomic block marked as durable in :class:`django.test.TestCase` now
  182. raises a ``RuntimeError``, the same as outside of tests.
  183. URLs
  184. ~~~~
  185. * ...
  186. Utilities
  187. ~~~~~~~~~
  188. * ...
  189. Validators
  190. ~~~~~~~~~~
  191. * ...
  192. .. _backwards-incompatible-4.1:
  193. Backwards incompatible changes in 4.1
  194. =====================================
  195. Database backend API
  196. --------------------
  197. This section describes changes that may be needed in third-party database
  198. backends.
  199. * ``BaseDatabaseFeatures.has_case_insensitive_like`` is changed from ``True``
  200. to ``False`` to reflect the behavior of most databases.
  201. * ``DatabaseIntrospection.get_key_columns()`` is removed. Use
  202. ``DatabaseIntrospection.get_relations()`` instead.
  203. * ``DatabaseOperations.ignore_conflicts_suffix_sql()`` method is replaced by
  204. ``DatabaseOperations.on_conflict_suffix_sql()`` that accepts the ``fields``,
  205. ``on_conflict``, ``update_fields``, and ``unique_fields`` arguments.
  206. * The ``ignore_conflicts`` argument of the
  207. ``DatabaseOperations.insert_statement()`` method is replaced by
  208. ``on_conflict`` that accepts ``django.db.models.constants.OnConflict``.
  209. :mod:`django.contrib.gis`
  210. -------------------------
  211. * Support for GDAL 2.1 is removed.
  212. Dropped support for MariaDB 10.2
  213. --------------------------------
  214. Upstream support for MariaDB 10.2 ends in May 2022. Django 4.1 supports MariaDB
  215. 10.3 and higher.
  216. Admin changelist searches spanning multi-valued relationships changes
  217. ---------------------------------------------------------------------
  218. Admin changelist searches using multiple search terms are now applied in a
  219. single call to ``filter()``, rather than in sequential ``filter()`` calls.
  220. For multi-valued relationships, this means that rows from the related model
  221. must match all terms rather than any term. For example, if ``search_fields``
  222. is set to ``['child__name', 'child__age']``, and a user searches for
  223. ``'Jamal 17'``, parent rows will be returned only if there is a relationship to
  224. some 17-year-old child named Jamal, rather than also returning parents who
  225. merely have a younger or older child named Jamal in addition to some other
  226. 17-year-old.
  227. See the :ref:`spanning-multi-valued-relationships` topic for more discussion of
  228. this difference. In Django 4.0 and earlier,
  229. :meth:`~django.contrib.admin.ModelAdmin.get_search_results` followed the
  230. second example query, but this undocumented behavior led to queries with
  231. excessive joins.
  232. Miscellaneous
  233. -------------
  234. * Related managers for :class:`~django.db.models.ForeignKey`,
  235. :class:`~django.db.models.ManyToManyField`, and
  236. :class:`~django.contrib.contenttypes.fields.GenericRelation` are now cached
  237. on the :class:`~django.db.models.Model` instance to which they belong.
  238. * The Django test runner now returns a non-zero error code for unexpected
  239. successes from tests marked with :py:func:`unittest.expectedFailure`.
  240. * :class:`~django.middleware.csrf.CsrfViewMiddleware` no longer masks the CSRF
  241. cookie like it does the CSRF token in the DOM.
  242. * :class:`~django.middleware.csrf.CsrfViewMiddleware` now uses
  243. ``request.META['CSRF_COOKIE']`` for storing the unmasked CSRF secret rather
  244. than a masked version. This is an undocumented, private API.
  245. * The :attr:`.ModelAdmin.actions` and
  246. :attr:`~django.contrib.admin.ModelAdmin.inlines` attributes now default to an
  247. empty tuple rather than an empty list to discourage unintended mutation.
  248. .. _deprecated-features-4.1:
  249. Features deprecated in 4.1
  250. ==========================
  251. Miscellaneous
  252. -------------
  253. * The context for sitemap index templates of a flat list of URLs is deprecated.
  254. Custom sitemap index templates should be updated for the adjusted
  255. :ref:`context variables <sitemap-index-context-variables>`, expecting a list
  256. of objects with ``location`` and optional ``lastmod`` attributes.
  257. * ``CSRF_COOKIE_MASKED`` transitional setting is deprecated.
  258. * The ``name`` argument of :func:`django.utils.functional.cached_property` is
  259. deprecated as it's unnecessary as of Python 3.6.
  260. * The ``opclasses`` argument of
  261. ``django.contrib.postgres.constraints.ExclusionConstraint`` is deprecated in
  262. favor of using :class:`OpClass() <django.contrib.postgres.indexes.OpClass>`
  263. in :attr:`.ExclusionConstraint.expressions`. To use it, you need to add
  264. ``'django.contrib.postgres'`` in your :setting:`INSTALLED_APPS`.
  265. After making this change, :djadmin:`makemigrations` will generate a new
  266. migration with two operations: ``RemoveConstraint`` and ``AddConstraint``.
  267. Since this change has no effect on the database schema,
  268. the :class:`~django.db.migrations.operations.SeparateDatabaseAndState`
  269. operation can be used to only update the migration state without running any
  270. SQL. Move the generated operations into the ``state_operations`` argument of
  271. :class:`~django.db.migrations.operations.SeparateDatabaseAndState`. For
  272. example::
  273. class Migration(migrations.Migration):
  274. ...
  275. operations = [
  276. migrations.SeparateDatabaseAndState(
  277. database_operations=[],
  278. state_operations=[
  279. migrations.RemoveConstraint(
  280. ...
  281. ),
  282. migrations.AddConstraint(
  283. ...
  284. ),
  285. ],
  286. ),
  287. ]
  288. * The undocumented ability to pass ``errors=None`` to
  289. :meth:`.SimpleTestCase.assertFormError` and
  290. :meth:`~.SimpleTestCase.assertFormsetError` is deprecated. Use ``errors=[]``
  291. instead.
  292. * The ``exc_info`` argument of the undocumented
  293. ``django.utils.log.log_response()`` function is replaced by ``exception``.
  294. * ``django.contrib.sessions.serializers.PickleSerializer`` is deprecated due to
  295. the risk of remote code execution.
  296. Features removed in 4.1
  297. =======================
  298. These features have reached the end of their deprecation cycle and are removed
  299. in Django 4.1.
  300. See :ref:`deprecated-features-3.2` for details on these changes, including how
  301. to remove usage of these features.
  302. * Support for assigning objects which don't support creating deep copies with
  303. ``copy.deepcopy()`` to class attributes in ``TestCase.setUpTestData()`` is
  304. removed.
  305. * Support for using a boolean value in
  306. :attr:`.BaseCommand.requires_system_checks` is removed.
  307. * The ``whitelist`` argument and ``domain_whitelist`` attribute of
  308. ``django.core.validators.EmailValidator`` are removed.
  309. * The ``default_app_config`` application configuration variable is removed.
  310. * ``TransactionTestCase.assertQuerysetEqual()`` no longer calls ``repr()`` on a
  311. queryset when compared to string values.
  312. * The ``django.core.cache.backends.memcached.MemcachedCache`` backend is
  313. removed.
  314. * Support for the pre-Django 3.2 format of messages used by
  315. ``django.contrib.messages.storage.cookie.CookieStorage`` is removed.