4.1.txt 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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. * ...
  99. :mod:`django.contrib.syndication`
  100. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  101. * ...
  102. Cache
  103. ~~~~~
  104. * ...
  105. CSRF
  106. ~~~~
  107. * ...
  108. Decorators
  109. ~~~~~~~~~~
  110. * ...
  111. Email
  112. ~~~~~
  113. * ...
  114. Error Reporting
  115. ~~~~~~~~~~~~~~~
  116. * ...
  117. File Storage
  118. ~~~~~~~~~~~~
  119. * ...
  120. File Uploads
  121. ~~~~~~~~~~~~
  122. * ...
  123. Forms
  124. ~~~~~
  125. * The new :meth:`~django.forms.BoundField.legend_tag` allows rendering field
  126. labels in ``<legend>`` tags via the new ``tag`` argument of
  127. :meth:`~django.forms.BoundField.label_tag`.
  128. Generic Views
  129. ~~~~~~~~~~~~~
  130. * ...
  131. Internationalization
  132. ~~~~~~~~~~~~~~~~~~~~
  133. * The :func:`~django.conf.urls.i18n.i18n_patterns` function now supports
  134. languages with both scripts and regions.
  135. Logging
  136. ~~~~~~~
  137. * ...
  138. Management Commands
  139. ~~~~~~~~~~~~~~~~~~~
  140. * :option:`makemigrations --no-input` now logs default answers and reasons why
  141. migrations cannot be created.
  142. * The new :option:`makemigrations --scriptable` options diverts log output and
  143. input prompts to ``stderr``, writing only paths of generated migration files
  144. to ``stdout``.
  145. Migrations
  146. ~~~~~~~~~~
  147. * ...
  148. Models
  149. ~~~~~~
  150. * The ``order_by`` argument of the
  151. :class:`~django.db.models.expressions.Window` expression now accepts string
  152. references to fields and transforms.
  153. * The new :setting:`CONN_HEALTH_CHECKS` setting allows enabling health checks
  154. for :ref:`persistent database connections <persistent-database-connections>`
  155. in order to reduce the number of failed requests, e.g. after database server
  156. restart.
  157. Requests and Responses
  158. ~~~~~~~~~~~~~~~~~~~~~~
  159. * ...
  160. Security
  161. ~~~~~~~~
  162. * ...
  163. Serialization
  164. ~~~~~~~~~~~~~
  165. * ...
  166. Signals
  167. ~~~~~~~
  168. * The :data:`~django.db.models.signals.pre_delete` and
  169. :data:`~django.db.models.signals.post_delete` signals now dispatch the
  170. ``origin`` of the deletion.
  171. Templates
  172. ~~~~~~~~~
  173. * :tfilter:`json_script` template filter now allows wrapping in a ``<script>``
  174. tag without the HTML ``id`` attribute.
  175. Tests
  176. ~~~~~
  177. * A nested atomic block marked as durable in :class:`django.test.TestCase` now
  178. raises a ``RuntimeError``, the same as outside of tests.
  179. URLs
  180. ~~~~
  181. * ...
  182. Utilities
  183. ~~~~~~~~~
  184. * ...
  185. Validators
  186. ~~~~~~~~~~
  187. * ...
  188. .. _backwards-incompatible-4.1:
  189. Backwards incompatible changes in 4.1
  190. =====================================
  191. Database backend API
  192. --------------------
  193. This section describes changes that may be needed in third-party database
  194. backends.
  195. * ``BaseDatabaseFeatures.has_case_insensitive_like`` is changed from ``True``
  196. to ``False`` to reflect the behavior of most databases.
  197. * ``DatabaseIntrospection.get_key_columns()`` is removed. Use
  198. ``DatabaseIntrospection.get_relations()`` instead.
  199. Dropped support for MariaDB 10.2
  200. --------------------------------
  201. Upstream support for MariaDB 10.2 ends in May 2022. Django 4.1 supports MariaDB
  202. 10.3 and higher.
  203. Admin changelist searches spanning multi-valued relationships changes
  204. ---------------------------------------------------------------------
  205. Admin changelist searches using multiple search terms are now applied in a
  206. single call to ``filter()``, rather than in sequential ``filter()`` calls.
  207. For multi-valued relationships, this means that rows from the related model
  208. must match all terms rather than any term. For example, if ``search_fields``
  209. is set to ``['child__name', 'child__age']``, and a user searches for
  210. ``'Jamal 17'``, parent rows will be returned only if there is a relationship to
  211. some 17-year-old child named Jamal, rather than also returning parents who
  212. merely have a younger or older child named Jamal in addition to some other
  213. 17-year-old.
  214. See the :ref:`spanning-multi-valued-relationships` topic for more discussion of
  215. this difference. In Django 4.0 and earlier,
  216. :meth:`~django.contrib.admin.ModelAdmin.get_search_results` followed the
  217. second example query, but this undocumented behavior led to queries with
  218. excessive joins.
  219. Miscellaneous
  220. -------------
  221. * Related managers for :class:`~django.db.models.ForeignKey`,
  222. :class:`~django.db.models.ManyToManyField`, and
  223. :class:`~django.contrib.contenttypes.fields.GenericRelation` are now cached
  224. on the :class:`~django.db.models.Model` instance to which they belong.
  225. * The Django test runner now returns a non-zero error code for unexpected
  226. successes from tests marked with :py:func:`unittest.expectedFailure`.
  227. * :class:`~django.middleware.csrf.CsrfViewMiddleware` no longer masks the CSRF
  228. cookie like it does the CSRF token in the DOM.
  229. * :class:`~django.middleware.csrf.CsrfViewMiddleware` now uses
  230. ``request.META['CSRF_COOKIE']`` for storing the unmasked CSRF secret rather
  231. than a masked version. This is an undocumented, private API.
  232. * The :attr:`.ModelAdmin.actions` and
  233. :attr:`~django.contrib.admin.ModelAdmin.inlines` attributes now default to an
  234. empty tuple rather than an empty list to discourage unintended mutation.
  235. .. _deprecated-features-4.1:
  236. Features deprecated in 4.1
  237. ==========================
  238. Miscellaneous
  239. -------------
  240. * The context for sitemap index templates of a flat list of URLs is deprecated.
  241. Custom sitemap index templates should be updated for the adjusted
  242. :ref:`context variables <sitemap-index-context-variables>`, expecting a list
  243. of objects with ``location`` and optional ``lastmod`` attributes.
  244. * ``CSRF_COOKIE_MASKED`` transitional setting is deprecated.
  245. * The ``name`` argument of :func:`django.utils.functional.cached_property` is
  246. deprecated as it's unnecessary as of Python 3.6.
  247. * The ``opclasses`` argument of
  248. ``django.contrib.postgres.constraints.ExclusionConstraint`` is deprecated in
  249. favor of using :class:`OpClass() <django.contrib.postgres.indexes.OpClass>`
  250. in :attr:`.ExclusionConstraint.expressions`. To use it, you need to add
  251. ``'django.contrib.postgres'`` in your :setting:`INSTALLED_APPS`.
  252. After making this change, :djadmin:`makemigrations` will generate a new
  253. migration with two operations: ``RemoveConstraint`` and ``AddConstraint``.
  254. Since this change has no effect on the database schema,
  255. the :class:`~django.db.migrations.operations.SeparateDatabaseAndState`
  256. operation can be used to only update the migration state without running any
  257. SQL. Move the generated operations into the ``state_operations`` argument of
  258. :class:`~django.db.migrations.operations.SeparateDatabaseAndState`. For
  259. example::
  260. class Migration(migrations.Migration):
  261. ...
  262. operations = [
  263. migrations.SeparateDatabaseAndState(
  264. database_operations=[],
  265. state_operations=[
  266. migrations.RemoveConstraint(
  267. ...
  268. ),
  269. migrations.AddConstraint(
  270. ...
  271. ),
  272. ],
  273. ),
  274. ]
  275. * The undocumented ability to pass ``errors=None`` to
  276. :meth:`.SimpleTestCase.assertFormError` and
  277. :meth:`~.SimpleTestCase.assertFormsetError` is deprecated. Use ``errors=[]``
  278. instead.
  279. * The ``exc_info`` argument of the undocumented
  280. ``django.utils.log.log_response()`` function is replaced by ``exception``.
  281. * ``django.contrib.sessions.serializers.PickleSerializer`` is deprecated due to
  282. the risk of remote code execution.
  283. Features removed in 4.1
  284. =======================
  285. These features have reached the end of their deprecation cycle and are removed
  286. in Django 4.1.
  287. See :ref:`deprecated-features-3.2` for details on these changes, including how
  288. to remove usage of these features.
  289. * Support for assigning objects which don't support creating deep copies with
  290. ``copy.deepcopy()`` to class attributes in ``TestCase.setUpTestData()`` is
  291. removed.
  292. * Support for using a boolean value in
  293. :attr:`.BaseCommand.requires_system_checks` is removed.
  294. * The ``whitelist`` argument and ``domain_whitelist`` attribute of
  295. ``django.core.validators.EmailValidator`` are removed.
  296. * The ``default_app_config`` application configuration variable is removed.
  297. * ``TransactionTestCase.assertQuerysetEqual()`` no longer calls ``repr()`` on a
  298. queryset when compared to string values.
  299. * The ``django.core.cache.backends.memcached.MemcachedCache`` backend is
  300. removed.
  301. * Support for the pre-Django 3.2 format of messages used by
  302. ``django.contrib.messages.storage.cookie.CookieStorage`` is removed.