3.1.txt 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. ============================================
  2. Django 3.1 release notes - UNDER DEVELOPMENT
  3. ============================================
  4. *Expected August 2020*
  5. Welcome to Django 3.1!
  6. These release notes cover the :ref:`new features <whats-new-3.1>`, as well as
  7. some :ref:`backwards incompatible changes <backwards-incompatible-3.1>` you'll
  8. want to be aware of when upgrading from Django 3.0 or earlier. We've
  9. :ref:`dropped some features<removed-features-3.1>` that have reached the end of
  10. their deprecation cycle, and we've :ref:`begun the deprecation process for
  11. some features <deprecated-features-3.1>`.
  12. See the :doc:`/howto/upgrade-version` guide if you're updating an existing
  13. project.
  14. Python compatibility
  15. ====================
  16. Django 3.1 supports Python 3.6, 3.7, and 3.8. We **highly recommend** and only
  17. officially support the latest release of each series.
  18. .. _whats-new-3.1:
  19. What's new in Django 3.1
  20. ========================
  21. Minor features
  22. --------------
  23. :mod:`django.contrib.admin`
  24. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  25. * The new ``django.contrib.admin.EmptyFieldListFilter`` for
  26. :attr:`.ModelAdmin.list_filter` allows filtering on empty values (empty
  27. strings and nulls) in the admin changelist view.
  28. :mod:`django.contrib.admindocs`
  29. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  30. * ...
  31. :mod:`django.contrib.auth`
  32. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  33. * The default iteration count for the PBKDF2 password hasher is increased from
  34. 180,000 to 216,000.
  35. * Added the :setting:`PASSWORD_RESET_TIMEOUT` setting to define the minimum
  36. number of seconds a password reset link is valid for. This is encouraged
  37. instead of deprecated ``PASSWORD_RESET_TIMEOUT_DAYS``, which will be removed
  38. in Django 4.0.
  39. :mod:`django.contrib.contenttypes`
  40. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  41. * ...
  42. :mod:`django.contrib.gis`
  43. ~~~~~~~~~~~~~~~~~~~~~~~~~
  44. * :lookup:`relate` lookup is now supported on MariaDB.
  45. * Added the :attr:`.LinearRing.is_counterclockwise` property.
  46. * :class:`~django.contrib.gis.db.models.functions.AsGeoJSON` is now supported
  47. on Oracle.
  48. * Added the :class:`~django.contrib.gis.db.models.functions.AsWKB` and
  49. :class:`~django.contrib.gis.db.models.functions.AsWKT` functions.
  50. :mod:`django.contrib.messages`
  51. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  52. * ...
  53. :mod:`django.contrib.postgres`
  54. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  55. * The new :class:`~django.contrib.postgres.indexes.BloomIndex` class allows
  56. creating ``bloom`` indexes in the database. The new
  57. :class:`~django.contrib.postgres.operations.BloomExtension` migration
  58. operation installs the ``bloom`` extension to add support for this index.
  59. * :meth:`~django.db.models.Model.get_FOO_display` now supports
  60. :class:`~django.contrib.postgres.fields.ArrayField` and
  61. :class:`~django.contrib.postgres.fields.RangeField`.
  62. * The new :lookup:`rangefield.lower_inc`, :lookup:`rangefield.lower_inf`,
  63. :lookup:`rangefield.upper_inc`, and :lookup:`rangefield.upper_inf` allows
  64. querying :class:`~django.contrib.postgres.fields.RangeField` by a bound type.
  65. * :lookup:`rangefield.contained_by` now supports
  66. :class:`~django.db.models.SmallAutoField`,
  67. :class:`~django.db.models.AutoField`,
  68. :class:`~django.db.models.BigAutoField`,
  69. :class:`~django.db.models.SmallIntegerField`, and
  70. :class:`~django.db.models.DecimalField`.
  71. * :class:`~django.contrib.postgres.search.SearchQuery` now supports
  72. ``'websearch'`` search type on PostgreSQL 11+.
  73. :mod:`django.contrib.redirects`
  74. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  75. * ...
  76. :mod:`django.contrib.sessions`
  77. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  78. * The :setting:`SESSION_COOKIE_SAMESITE` setting now allows ``'None'`` (string)
  79. value to explicitly state that the cookie is sent with all same-site and
  80. cross-site requests.
  81. :mod:`django.contrib.sitemaps`
  82. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  83. * ...
  84. :mod:`django.contrib.sites`
  85. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  86. * ...
  87. :mod:`django.contrib.staticfiles`
  88. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  89. * The :setting:`STATICFILES_DIRS` setting now supports :class:`pathlib.Path`.
  90. :mod:`django.contrib.syndication`
  91. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  92. * ...
  93. Cache
  94. ~~~~~
  95. * The :func:`~django.views.decorators.cache.cache_control` decorator and
  96. :func:`~django.utils.cache.patch_cache_control` method now support multiple
  97. field names in the ``no-cache`` directive for the ``Cache-Control`` header,
  98. according to :rfc:`7234#section-5.2.2.2`.
  99. * :meth:`~django.core.caches.cache.delete` now returns ``True`` if the key was
  100. successfully deleted, ``False`` otherwise.
  101. CSRF
  102. ~~~~
  103. * The :setting:`CSRF_COOKIE_SAMESITE` setting now allows ``'None'`` (string)
  104. value to explicitly state that the cookie is sent with all same-site and
  105. cross-site requests.
  106. Email
  107. ~~~~~
  108. * The :setting:`EMAIL_FILE_PATH` setting, used by the :ref:`file email backend
  109. <topic-email-file-backend>`, now supports :class:`pathlib.Path`.
  110. Error Reporting
  111. ~~~~~~~~~~~~~~~
  112. * The new :attr:`.SafeExceptionReporterFilter.cleansed_substitute` and
  113. :attr:`.SafeExceptionReporterFilter.hidden_settings` attributes allow
  114. customization of sensitive settings filtering in exception reports.
  115. * The technical 404 debug view now respects
  116. :setting:`DEFAULT_EXCEPTION_REPORTER_FILTER` when applying settings
  117. filtering.
  118. File Storage
  119. ~~~~~~~~~~~~
  120. * ``FileSystemStorage.save()`` method now supports :class:`pathlib.Path`.
  121. File Uploads
  122. ~~~~~~~~~~~~
  123. * ...
  124. Forms
  125. ~~~~~
  126. * :class:`~django.forms.ModelChoiceIterator`, used by
  127. :class:`~django.forms.ModelChoiceField` and
  128. :class:`~django.forms.ModelMultipleChoiceField`, now uses
  129. :class:`~django.forms.ModelChoiceIteratorValue` that can be used by widgets
  130. to access model instances. See :ref:`iterating-relationship-choices` for
  131. details.
  132. * :class:`django.forms.DateTimeField` now accepts dates in a subset of ISO 8601
  133. datetime formats, including optional timezone (e.g. ``2019-10-10T06:47``,
  134. ``2019-10-10T06:47:23+04:00``, or ``2019-10-10T06:47:23Z``). Additionally, it
  135. now uses ``DATE_INPUT_FORMATS`` in addition to ``DATETIME_INPUT_FORMATS``
  136. when converting a field input to a ``datetime`` value.
  137. Generic Views
  138. ~~~~~~~~~~~~~
  139. * ...
  140. Internationalization
  141. ~~~~~~~~~~~~~~~~~~~~
  142. * The :setting:`LANGUAGE_COOKIE_SAMESITE` setting now allows ``'None'``
  143. (string) value to explicitly state that the cookie is sent with all same-site
  144. and cross-site requests.
  145. * Added support and translations for the Algerian Arabic language.
  146. Logging
  147. ~~~~~~~
  148. * ...
  149. Management Commands
  150. ~~~~~~~~~~~~~~~~~~~
  151. * ...
  152. Migrations
  153. ~~~~~~~~~~
  154. * Migrations are now loaded also from directories without ``__init__.py``
  155. files.
  156. Models
  157. ~~~~~~
  158. * The new :class:`~django.db.models.functions.ExtractIsoWeekDay` function
  159. extracts ISO-8601 week days from :class:`~django.db.models.DateField` and
  160. :class:`~django.db.models.DateTimeField`, and the new :lookup:`iso_week_day`
  161. lookup allows querying by an ISO-8601 day of week.
  162. * :meth:`.QuerySet.explain` now supports:
  163. * ``TREE`` format on MySQL 8.0.16+,
  164. * ``analyze`` option on MySQL 8.0.18+ and MariaDB.
  165. * Added :class:`~django.db.models.PositiveBigIntegerField` which acts much like
  166. a :class:`~django.db.models.PositiveIntegerField` except that it only allows
  167. values under a certain (database-dependent) limit. Values from ``0`` to
  168. ``9223372036854775807`` are safe in all databases supported by Django.
  169. * The new :class:`~django.db.models.RESTRICT` option for
  170. :attr:`~django.db.models.ForeignKey.on_delete` argument of ``ForeignKey`` and
  171. ``OneToOneField`` emulates the behavior of the SQL constraint ``ON DELETE
  172. RESTRICT``.
  173. * :attr:`.CheckConstraint.check` now supports boolean expressions.
  174. * The :meth:`.RelatedManager.add`, :meth:`~.RelatedManager.create`, and
  175. :meth:`~.RelatedManager.set` methods now accept callables as values in the
  176. ``through_defaults`` argument.
  177. Pagination
  178. ~~~~~~~~~~
  179. * :class:`~django.core.paginator.Paginator` can now be iterated over to yield
  180. its pages.
  181. Requests and Responses
  182. ~~~~~~~~~~~~~~~~~~~~~~
  183. * If :setting:`ALLOWED_HOSTS` is empty and ``DEBUG=True``, subdomains of
  184. localhost are now allowed in the ``Host`` header, e.g. ``static.localhost``.
  185. * :meth:`.HttpResponse.set_cookie` and :meth:`.HttpResponse.set_signed_cookie`
  186. now allow using ``samesite='None'`` (string) to explicitly state that the
  187. cookie is sent with all same-site and cross-site requests.
  188. Serialization
  189. ~~~~~~~~~~~~~
  190. * ...
  191. Signals
  192. ~~~~~~~
  193. * ...
  194. Templates
  195. ~~~~~~~~~
  196. * The renamed :ttag:`translate` and :ttag:`blocktranslate` template tags are
  197. introduced for internationalization in template code. The older :ttag:`trans`
  198. and :ttag:`blocktrans` template tags aliases continue to work, and will be
  199. retained for the foreseeable future.
  200. Tests
  201. ~~~~~
  202. * :class:`~django.test.SimpleTestCase` now implements the ``debug()`` method to
  203. allow running a test without collecting the result and catching exceptions.
  204. This can be used to support running tests under a debugger.
  205. * The new :setting:`MIGRATE <TEST_MIGRATE>` test database setting allows
  206. disabling of migrations during a test database creation.
  207. * Django test runner now supports a :option:`test --buffer` option to discard
  208. output for passing tests.
  209. URLs
  210. ~~~~
  211. * :ref:`Path converters <registering-custom-path-converters>` can now raise
  212. ``ValueError`` in ``to_url()`` to indicate no match when reversing URLs.
  213. Utilities
  214. ~~~~~~~~~
  215. * :func:`~django.utils.encoding.filepath_to_uri` now supports
  216. :class:`pathlib.Path`.
  217. * :func:`~django.utils.dateparse.parse_duration` now supports comma separators
  218. for decimal fractions in the ISO 8601 format.
  219. * :func:`~django.utils.dateparse.parse_datetime`,
  220. :func:`~django.utils.dateparse.parse_duration`, and
  221. :func:`~django.utils.dateparse.parse_time` now support comma separators for
  222. milliseconds.
  223. Validators
  224. ~~~~~~~~~~
  225. * ...
  226. Miscellaneous
  227. ~~~~~~~~~~~~~
  228. * The SQLite backend now supports :class:`pathlib.Path` for the ``NAME``
  229. setting.
  230. * The ``settings.py`` generated by the :djadmin:`startproject` command now uses
  231. :class:`pathlib.Path` instead of :mod:`os.path` for building filesystem
  232. paths.
  233. * The :setting:`TIME_ZONE <DATABASE-TIME_ZONE>` setting is now allowed on
  234. databases that support time zones.
  235. .. _backwards-incompatible-3.1:
  236. Backwards incompatible changes in 3.1
  237. =====================================
  238. Database backend API
  239. --------------------
  240. This section describes changes that may be needed in third-party database
  241. backends.
  242. * ``DatabaseOperations.fetch_returned_insert_columns()`` now requires an
  243. additional ``returning_params`` argument.
  244. * ``connection.timezone`` property is now ``'UTC'`` by default, or the
  245. :setting:`TIME_ZONE <DATABASE-TIME_ZONE>` when :setting:`USE_TZ` is ``True``
  246. on databases that support time zones. Previously, it was ``None`` on
  247. databases that support time zones.
  248. Dropped support for MariaDB 10.1
  249. --------------------------------
  250. Upstream support for MariaDB 10.1 ends in October 2020. Django 3.1 supports
  251. MariaDB 10.2 and higher.
  252. Miscellaneous
  253. -------------
  254. * The cache keys used by :ttag:`cache` and generated by
  255. :func:`~django.core.cache.utils.make_template_fragment_key` are different
  256. from the keys generated by older versions of Django. After upgrading to
  257. Django 3.1, the first request to any previously cached template fragment will
  258. be a cache miss.
  259. * The compatibility imports of ``django.core.exceptions.EmptyResultSet`` in
  260. ``django.db.models.query``, ``django.db.models.sql``, and
  261. ``django.db.models.sql.datastructures`` are removed.
  262. * The compatibility import of ``django.core.exceptions.FieldDoesNotExist`` in
  263. ``django.db.models.fields`` is removed.
  264. * The compatibility imports of ``django.forms.utils.pretty_name()`` and
  265. ``django.forms.boundfield.BoundField`` in ``django.forms.forms`` are removed.
  266. * The compatibility imports of ``Context``, ``ContextPopException``, and
  267. ``RequestContext`` in ``django.template.base`` are removed.
  268. * The compatibility import of
  269. ``django.contrib.admin.helpers.ACTION_CHECKBOX_NAME`` in
  270. ``django.contrib.admin`` is removed.
  271. * The :setting:`STATIC_URL` and :setting:`MEDIA_URL` settings set to relative
  272. paths are now prefixed by the server-provided value of ``SCRIPT_NAME`` (or
  273. ``/`` if not set). This change should not affect settings set to valid URLs
  274. or absolute paths.
  275. * :class:`~django.middleware.http.ConditionalGetMiddleware` no longer adds the
  276. ``ETag`` header to responses with an empty
  277. :attr:`~django.http.HttpResponse.content`.
  278. * ``django.utils.decorators.classproperty()`` decorator is moved to
  279. ``django.utils.functional.classproperty()``.
  280. * :tfilter:`floatformat` template filter now outputs (positive) ``0`` for
  281. negative numbers which round to zero.
  282. * :attr:`Meta.ordering <django.db.models.Options.ordering>` and
  283. :attr:`Meta.unique_together <django.db.models.Options.unique_together>`
  284. options on models in ``django.contrib`` modules that were formerly tuples are
  285. now lists.
  286. * The admin calendar widget now handles two-digit years according to the Open
  287. Group Specification, i.e. values between 69 and 99 are mapped to the previous
  288. century, and values between 0 and 68 are mapped to the current century.
  289. * Date-only formats are removed from the default list for
  290. :setting:`DATETIME_INPUT_FORMATS`.
  291. * The :class:`~django.forms.FileInput` widget no longer renders with the
  292. ``required`` HTML attribute when initial data exists.
  293. .. _deprecated-features-3.1:
  294. Features deprecated in 3.1
  295. ==========================
  296. Miscellaneous
  297. -------------
  298. * ``PASSWORD_RESET_TIMEOUT_DAYS`` setting is deprecated in favor of
  299. :setting:`PASSWORD_RESET_TIMEOUT`.
  300. * The undocumented usage of the :lookup:`isnull` lookup with non-boolean values
  301. as the right-hand side is deprecated, use ``True`` or ``False`` instead.
  302. * The barely documented ``django.db.models.query_utils.InvalidQuery`` exception
  303. class is deprecated in favor of
  304. :class:`~django.core.exceptions.FieldDoesNotExist` and
  305. :class:`~django.core.exceptions.FieldError`.
  306. * The ``django-admin.py`` entry point is deprecated in favor of
  307. ``django-admin``.
  308. .. _removed-features-3.1:
  309. Features removed in 3.1
  310. =======================
  311. These features have reached the end of their deprecation cycle and are removed
  312. in Django 3.1.
  313. See :ref:`deprecated-features-2.2` for details on these changes, including how
  314. to remove usage of these features.
  315. * ``django.utils.timezone.FixedOffset`` is removed.
  316. * ``django.core.paginator.QuerySetPaginator`` is removed.
  317. * A model's ``Meta.ordering`` doesn't affect ``GROUP BY`` queries.
  318. * ``django.contrib.postgres.fields.FloatRangeField`` and
  319. ``django.contrib.postgres.forms.FloatRangeField`` are removed.
  320. * The ``FILE_CHARSET`` setting is removed.
  321. * ``django.contrib.staticfiles.storage.CachedStaticFilesStorage`` is removed.
  322. * The ``RemoteUserBackend.configure_user()`` method requires ``request`` as the
  323. first positional argument.
  324. * Support for ``SimpleTestCase.allow_database_queries`` and
  325. ``TransactionTestCase.multi_db`` is removed.