3.1.txt 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  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. * Filters in the right sidebar of the admin changelist view now contains a link
  29. to clear all filters.
  30. :mod:`django.contrib.admindocs`
  31. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  32. * ...
  33. :mod:`django.contrib.auth`
  34. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  35. * The default iteration count for the PBKDF2 password hasher is increased from
  36. 180,000 to 216,000.
  37. * Added the :setting:`PASSWORD_RESET_TIMEOUT` setting to define the minimum
  38. number of seconds a password reset link is valid for. This is encouraged
  39. instead of deprecated ``PASSWORD_RESET_TIMEOUT_DAYS``, which will be removed
  40. in Django 4.0.
  41. * The password reset mechanism now uses the SHA-256 hashing algorithm. Support
  42. for tokens that use the old hashing algorithm remains until Django 4.0.
  43. :mod:`django.contrib.contenttypes`
  44. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  45. * ...
  46. :mod:`django.contrib.gis`
  47. ~~~~~~~~~~~~~~~~~~~~~~~~~
  48. * :lookup:`relate` lookup is now supported on MariaDB.
  49. * Added the :attr:`.LinearRing.is_counterclockwise` property.
  50. * :class:`~django.contrib.gis.db.models.functions.AsGeoJSON` is now supported
  51. on Oracle.
  52. * Added the :class:`~django.contrib.gis.db.models.functions.AsWKB` and
  53. :class:`~django.contrib.gis.db.models.functions.AsWKT` functions.
  54. :mod:`django.contrib.messages`
  55. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  56. * ...
  57. :mod:`django.contrib.postgres`
  58. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  59. * The new :class:`~django.contrib.postgres.indexes.BloomIndex` class allows
  60. creating ``bloom`` indexes in the database. The new
  61. :class:`~django.contrib.postgres.operations.BloomExtension` migration
  62. operation installs the ``bloom`` extension to add support for this index.
  63. * :meth:`~django.db.models.Model.get_FOO_display` now supports
  64. :class:`~django.contrib.postgres.fields.ArrayField` and
  65. :class:`~django.contrib.postgres.fields.RangeField`.
  66. * The new :lookup:`rangefield.lower_inc`, :lookup:`rangefield.lower_inf`,
  67. :lookup:`rangefield.upper_inc`, and :lookup:`rangefield.upper_inf` allows
  68. querying :class:`~django.contrib.postgres.fields.RangeField` by a bound type.
  69. * :lookup:`rangefield.contained_by` now supports
  70. :class:`~django.db.models.SmallAutoField`,
  71. :class:`~django.db.models.AutoField`,
  72. :class:`~django.db.models.BigAutoField`,
  73. :class:`~django.db.models.SmallIntegerField`, and
  74. :class:`~django.db.models.DecimalField`.
  75. * :class:`~django.contrib.postgres.search.SearchQuery` now supports
  76. ``'websearch'`` search type on PostgreSQL 11+.
  77. :mod:`django.contrib.redirects`
  78. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  79. * ...
  80. :mod:`django.contrib.sessions`
  81. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  82. * The :setting:`SESSION_COOKIE_SAMESITE` setting now allows ``'None'`` (string)
  83. value to explicitly state that the cookie is sent with all same-site and
  84. cross-site requests.
  85. :mod:`django.contrib.sitemaps`
  86. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  87. * ...
  88. :mod:`django.contrib.sites`
  89. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  90. * ...
  91. :mod:`django.contrib.staticfiles`
  92. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  93. * The :setting:`STATICFILES_DIRS` setting now supports :class:`pathlib.Path`.
  94. :mod:`django.contrib.syndication`
  95. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  96. * ...
  97. Cache
  98. ~~~~~
  99. * The :func:`~django.views.decorators.cache.cache_control` decorator and
  100. :func:`~django.utils.cache.patch_cache_control` method now support multiple
  101. field names in the ``no-cache`` directive for the ``Cache-Control`` header,
  102. according to :rfc:`7234#section-5.2.2.2`.
  103. * :meth:`~django.core.caches.cache.delete` now returns ``True`` if the key was
  104. successfully deleted, ``False`` otherwise.
  105. CSRF
  106. ~~~~
  107. * The :setting:`CSRF_COOKIE_SAMESITE` setting now allows ``'None'`` (string)
  108. value to explicitly state that the cookie is sent with all same-site and
  109. cross-site requests.
  110. Email
  111. ~~~~~
  112. * The :setting:`EMAIL_FILE_PATH` setting, used by the :ref:`file email backend
  113. <topic-email-file-backend>`, now supports :class:`pathlib.Path`.
  114. Error Reporting
  115. ~~~~~~~~~~~~~~~
  116. * :class:`django.views.debug.SafeExceptionReporterFilter` now filters sensitive
  117. values from ``request.META`` in exception reports.
  118. * The new :attr:`.SafeExceptionReporterFilter.cleansed_substitute` and
  119. :attr:`.SafeExceptionReporterFilter.hidden_settings` attributes allow
  120. customization of sensitive settings and ``request.META`` filtering in
  121. exception reports.
  122. * The technical 404 debug view now respects
  123. :setting:`DEFAULT_EXCEPTION_REPORTER_FILTER` when applying settings
  124. filtering.
  125. * The new :setting:`DEFAULT_EXCEPTION_REPORTER` allows providing a
  126. :class:`django.views.debug.ExceptionReporter` subclass to customize exception
  127. report generation. See :ref:`custom-error-reports` for details.
  128. File Storage
  129. ~~~~~~~~~~~~
  130. * ``FileSystemStorage.save()`` method now supports :class:`pathlib.Path`.
  131. File Uploads
  132. ~~~~~~~~~~~~
  133. * ...
  134. Forms
  135. ~~~~~
  136. * :class:`~django.forms.ModelChoiceIterator`, used by
  137. :class:`~django.forms.ModelChoiceField` and
  138. :class:`~django.forms.ModelMultipleChoiceField`, now uses
  139. :class:`~django.forms.ModelChoiceIteratorValue` that can be used by widgets
  140. to access model instances. See :ref:`iterating-relationship-choices` for
  141. details.
  142. * :class:`django.forms.DateTimeField` now accepts dates in a subset of ISO 8601
  143. datetime formats, including optional timezone (e.g. ``2019-10-10T06:47``,
  144. ``2019-10-10T06:47:23+04:00``, or ``2019-10-10T06:47:23Z``). Additionally, it
  145. now uses ``DATE_INPUT_FORMATS`` in addition to ``DATETIME_INPUT_FORMATS``
  146. when converting a field input to a ``datetime`` value.
  147. Generic Views
  148. ~~~~~~~~~~~~~
  149. * ...
  150. Internationalization
  151. ~~~~~~~~~~~~~~~~~~~~
  152. * The :setting:`LANGUAGE_COOKIE_SAMESITE` setting now allows ``'None'``
  153. (string) value to explicitly state that the cookie is sent with all same-site
  154. and cross-site requests.
  155. * Added support and translations for the Algerian Arabic language.
  156. Logging
  157. ~~~~~~~
  158. * ...
  159. Management Commands
  160. ~~~~~~~~~~~~~~~~~~~
  161. * The new :option:`check --database` option allows specifying database aliases
  162. for running the ``database`` system checks. Previously these checks were
  163. enabled for all configured :setting:`DATABASES` by passing the ``database``
  164. tag to the command.
  165. Migrations
  166. ~~~~~~~~~~
  167. * Migrations are now loaded also from directories without ``__init__.py``
  168. files.
  169. Models
  170. ~~~~~~
  171. * The new :class:`~django.db.models.functions.ExtractIsoWeekDay` function
  172. extracts ISO-8601 week days from :class:`~django.db.models.DateField` and
  173. :class:`~django.db.models.DateTimeField`, and the new :lookup:`iso_week_day`
  174. lookup allows querying by an ISO-8601 day of week.
  175. * :meth:`.QuerySet.explain` now supports:
  176. * ``TREE`` format on MySQL 8.0.16+,
  177. * ``analyze`` option on MySQL 8.0.18+ and MariaDB.
  178. * Added :class:`~django.db.models.PositiveBigIntegerField` which acts much like
  179. a :class:`~django.db.models.PositiveIntegerField` except that it only allows
  180. values under a certain (database-dependent) limit. Values from ``0`` to
  181. ``9223372036854775807`` are safe in all databases supported by Django.
  182. * The new :class:`~django.db.models.RESTRICT` option for
  183. :attr:`~django.db.models.ForeignKey.on_delete` argument of ``ForeignKey`` and
  184. ``OneToOneField`` emulates the behavior of the SQL constraint ``ON DELETE
  185. RESTRICT``.
  186. * :attr:`.CheckConstraint.check` now supports boolean expressions.
  187. * The :meth:`.RelatedManager.add`, :meth:`~.RelatedManager.create`, and
  188. :meth:`~.RelatedManager.set` methods now accept callables as values in the
  189. ``through_defaults`` argument.
  190. Pagination
  191. ~~~~~~~~~~
  192. * :class:`~django.core.paginator.Paginator` can now be iterated over to yield
  193. its pages.
  194. Requests and Responses
  195. ~~~~~~~~~~~~~~~~~~~~~~
  196. * If :setting:`ALLOWED_HOSTS` is empty and ``DEBUG=True``, subdomains of
  197. localhost are now allowed in the ``Host`` header, e.g. ``static.localhost``.
  198. * :meth:`.HttpResponse.set_cookie` and :meth:`.HttpResponse.set_signed_cookie`
  199. now allow using ``samesite='None'`` (string) to explicitly state that the
  200. cookie is sent with all same-site and cross-site requests.
  201. * The new :meth:`.HttpRequest.accepts` method returns whether the request
  202. accepts the given MIME type according to the ``Accept`` HTTP header.
  203. .. _whats-new-security-3.1:
  204. Security
  205. ~~~~~~~~
  206. * The :setting:`SECURE_REFERRER_POLICY` setting now defaults to
  207. ``'same-origin'``. With this configured,
  208. :class:`~django.middleware.security.SecurityMiddleware` sets the
  209. :ref:`referrer-policy` header to ``same-origin`` on all responses that do not
  210. already have it. This prevents the ``Referer`` header being sent to other
  211. origins. If you need the previous behavior, explicitly set
  212. :setting:`SECURE_REFERRER_POLICY` to ``None``.
  213. Serialization
  214. ~~~~~~~~~~~~~
  215. * ...
  216. Signals
  217. ~~~~~~~
  218. * ...
  219. Templates
  220. ~~~~~~~~~
  221. * The renamed :ttag:`translate` and :ttag:`blocktranslate` template tags are
  222. introduced for internationalization in template code. The older :ttag:`trans`
  223. and :ttag:`blocktrans` template tags aliases continue to work, and will be
  224. retained for the foreseeable future.
  225. * The :ttag:`include` template tag now accepts iterables of template names.
  226. Tests
  227. ~~~~~
  228. * :class:`~django.test.SimpleTestCase` now implements the ``debug()`` method to
  229. allow running a test without collecting the result and catching exceptions.
  230. This can be used to support running tests under a debugger.
  231. * The new :setting:`MIGRATE <TEST_MIGRATE>` test database setting allows
  232. disabling of migrations during a test database creation.
  233. * Django test runner now supports a :option:`test --buffer` option to discard
  234. output for passing tests.
  235. * :class:`~django.test.runner.DiscoverRunner` now skips running the system
  236. checks on databases not :ref:`referenced by tests<testing-multi-db>`.
  237. URLs
  238. ~~~~
  239. * :ref:`Path converters <registering-custom-path-converters>` can now raise
  240. ``ValueError`` in ``to_url()`` to indicate no match when reversing URLs.
  241. Utilities
  242. ~~~~~~~~~
  243. * :func:`~django.utils.encoding.filepath_to_uri` now supports
  244. :class:`pathlib.Path`.
  245. * :func:`~django.utils.dateparse.parse_duration` now supports comma separators
  246. for decimal fractions in the ISO 8601 format.
  247. * :func:`~django.utils.dateparse.parse_datetime`,
  248. :func:`~django.utils.dateparse.parse_duration`, and
  249. :func:`~django.utils.dateparse.parse_time` now support comma separators for
  250. milliseconds.
  251. Validators
  252. ~~~~~~~~~~
  253. * ...
  254. Miscellaneous
  255. ~~~~~~~~~~~~~
  256. * The SQLite backend now supports :class:`pathlib.Path` for the ``NAME``
  257. setting.
  258. * The ``settings.py`` generated by the :djadmin:`startproject` command now uses
  259. :class:`pathlib.Path` instead of :mod:`os.path` for building filesystem
  260. paths.
  261. * The :setting:`TIME_ZONE <DATABASE-TIME_ZONE>` setting is now allowed on
  262. databases that support time zones.
  263. .. _backwards-incompatible-3.1:
  264. Backwards incompatible changes in 3.1
  265. =====================================
  266. Database backend API
  267. --------------------
  268. This section describes changes that may be needed in third-party database
  269. backends.
  270. * ``DatabaseOperations.fetch_returned_insert_columns()`` now requires an
  271. additional ``returning_params`` argument.
  272. * ``connection.timezone`` property is now ``'UTC'`` by default, or the
  273. :setting:`TIME_ZONE <DATABASE-TIME_ZONE>` when :setting:`USE_TZ` is ``True``
  274. on databases that support time zones. Previously, it was ``None`` on
  275. databases that support time zones.
  276. * ``connection._nodb_connection`` property is changed to the
  277. ``connection._nodb_cursor()`` method and now returns a context manager that
  278. yields a cursor and automatically closes the cursor and connection upon
  279. exiting the ``with`` statement.
  280. Dropped support for MariaDB 10.1
  281. --------------------------------
  282. Upstream support for MariaDB 10.1 ends in October 2020. Django 3.1 supports
  283. MariaDB 10.2 and higher.
  284. Miscellaneous
  285. -------------
  286. * The cache keys used by :ttag:`cache` and generated by
  287. :func:`~django.core.cache.utils.make_template_fragment_key` are different
  288. from the keys generated by older versions of Django. After upgrading to
  289. Django 3.1, the first request to any previously cached template fragment will
  290. be a cache miss.
  291. * The logic behind the decision to return a redirection fallback or a 204 HTTP
  292. response from the :func:`~django.views.i18n.set_language` view is now based
  293. on the ``Accept`` HTTP header instead of the ``X-Requested-With`` HTTP header
  294. presence.
  295. * The compatibility imports of ``django.core.exceptions.EmptyResultSet`` in
  296. ``django.db.models.query``, ``django.db.models.sql``, and
  297. ``django.db.models.sql.datastructures`` are removed.
  298. * The compatibility import of ``django.core.exceptions.FieldDoesNotExist`` in
  299. ``django.db.models.fields`` is removed.
  300. * The compatibility imports of ``django.forms.utils.pretty_name()`` and
  301. ``django.forms.boundfield.BoundField`` in ``django.forms.forms`` are removed.
  302. * The compatibility imports of ``Context``, ``ContextPopException``, and
  303. ``RequestContext`` in ``django.template.base`` are removed.
  304. * The compatibility import of
  305. ``django.contrib.admin.helpers.ACTION_CHECKBOX_NAME`` in
  306. ``django.contrib.admin`` is removed.
  307. * The :setting:`STATIC_URL` and :setting:`MEDIA_URL` settings set to relative
  308. paths are now prefixed by the server-provided value of ``SCRIPT_NAME`` (or
  309. ``/`` if not set). This change should not affect settings set to valid URLs
  310. or absolute paths.
  311. * :class:`~django.middleware.http.ConditionalGetMiddleware` no longer adds the
  312. ``ETag`` header to responses with an empty
  313. :attr:`~django.http.HttpResponse.content`.
  314. * ``django.utils.decorators.classproperty()`` decorator is moved to
  315. ``django.utils.functional.classproperty()``.
  316. * :tfilter:`floatformat` template filter now outputs (positive) ``0`` for
  317. negative numbers which round to zero.
  318. * :attr:`Meta.ordering <django.db.models.Options.ordering>` and
  319. :attr:`Meta.unique_together <django.db.models.Options.unique_together>`
  320. options on models in ``django.contrib`` modules that were formerly tuples are
  321. now lists.
  322. * The admin calendar widget now handles two-digit years according to the Open
  323. Group Specification, i.e. values between 69 and 99 are mapped to the previous
  324. century, and values between 0 and 68 are mapped to the current century.
  325. * Date-only formats are removed from the default list for
  326. :setting:`DATETIME_INPUT_FORMATS`.
  327. * The :class:`~django.forms.FileInput` widget no longer renders with the
  328. ``required`` HTML attribute when initial data exists.
  329. * The undocumented ``django.views.debug.ExceptionReporterFilter`` class is
  330. removed. As per the :ref:`custom-error-reports` documentation, classes to be
  331. used with :setting:`DEFAULT_EXCEPTION_REPORTER_FILTER` needs to inherit from
  332. :class:`django.views.debug.SafeExceptionReporterFilter`.
  333. * The cache timeout set by :func:`~django.views.decorators.cache.cache_page`
  334. decorator now takes precedence over the ``max-age`` directive from the
  335. ``Cache-Control`` header.
  336. * Providing a non-local remote field in the :attr:`.ForeignKey.to_field`
  337. argument now raises :class:`~django.core.exceptions.FieldError`.
  338. * :setting:`SECURE_REFERRER_POLICY` now defaults to ``'same-origin'``. See the
  339. *What's New* :ref:`Security section <whats-new-security-3.1>` above for more
  340. details.
  341. * :djadmin:`check` management command now runs the ``database`` system checks
  342. only for database aliases specified using :option:`check --database` option.
  343. * :djadmin:`migrate` management command now runs the ``database`` system checks
  344. only for a database to migrate.
  345. .. _deprecated-features-3.1:
  346. Features deprecated in 3.1
  347. ==========================
  348. Miscellaneous
  349. -------------
  350. * ``PASSWORD_RESET_TIMEOUT_DAYS`` setting is deprecated in favor of
  351. :setting:`PASSWORD_RESET_TIMEOUT`.
  352. * The undocumented usage of the :lookup:`isnull` lookup with non-boolean values
  353. as the right-hand side is deprecated, use ``True`` or ``False`` instead.
  354. * The barely documented ``django.db.models.query_utils.InvalidQuery`` exception
  355. class is deprecated in favor of
  356. :class:`~django.core.exceptions.FieldDoesNotExist` and
  357. :class:`~django.core.exceptions.FieldError`.
  358. * The ``django-admin.py`` entry point is deprecated in favor of
  359. ``django-admin``.
  360. * The ``HttpRequest.is_ajax()`` method is deprecated as it relied on a
  361. jQuery-specific way of signifying AJAX calls, while current usage tends to
  362. use the JavaScript `Fetch API
  363. <https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API>`_. Depending on
  364. your use case, you can either write your own AJAX detection method, or use
  365. the new :meth:`.HttpRequest.accepts` method if your code depends on the
  366. client ``Accept`` HTTP header.
  367. If you are writing your own AJAX detection method, ``request.is_ajax()`` can
  368. be reproduced exactly as
  369. ``request.headers.get('x-requested-with') == 'XMLHttpRequest'``.
  370. * Passing ``None`` as the first argument to
  371. ``django.utils.deprecation.MiddlewareMixin.__init__()`` is deprecated.
  372. * The encoding format of cookies values used by
  373. :class:`~django.contrib.messages.storage.cookie.CookieStorage` is different
  374. from the format generated by older versions of Django. Support for the old
  375. format remains until Django 4.0.
  376. .. _removed-features-3.1:
  377. Features removed in 3.1
  378. =======================
  379. These features have reached the end of their deprecation cycle and are removed
  380. in Django 3.1.
  381. See :ref:`deprecated-features-2.2` for details on these changes, including how
  382. to remove usage of these features.
  383. * ``django.utils.timezone.FixedOffset`` is removed.
  384. * ``django.core.paginator.QuerySetPaginator`` is removed.
  385. * A model's ``Meta.ordering`` doesn't affect ``GROUP BY`` queries.
  386. * ``django.contrib.postgres.fields.FloatRangeField`` and
  387. ``django.contrib.postgres.forms.FloatRangeField`` are removed.
  388. * The ``FILE_CHARSET`` setting is removed.
  389. * ``django.contrib.staticfiles.storage.CachedStaticFilesStorage`` is removed.
  390. * The ``RemoteUserBackend.configure_user()`` method requires ``request`` as the
  391. first positional argument.
  392. * Support for ``SimpleTestCase.allow_database_queries`` and
  393. ``TransactionTestCase.multi_db`` is removed.