3.1.txt 18 KB

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