3.1.txt 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850
  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. Asynchronous views and middleware support
  22. -----------------------------------------
  23. Django now supports a fully asynchronous request path, including:
  24. * :ref:`Asynchronous views <async-views>`
  25. * :ref:`Asynchronous middleware <async-middleware>`
  26. * :ref:`Asynchronous tests and test client <async-tests>`
  27. To get started with async views, you need to declare a view using
  28. ``async def``::
  29. async def my_view(request):
  30. await asyncio.sleep(0.5)
  31. return HttpResponse('Hello, async world!')
  32. All asynchronous features are supported whether you are running under WSGI or
  33. ASGI mode. However, there will be performance penalties using async code in
  34. WSGI mode. You can read more about the specifics in :doc:`/topics/async`
  35. documentation.
  36. You are free to mix async and sync views, middleware, and tests as much as you
  37. want. Django will ensure that you always end up with the right execution
  38. context. We expect most projects will keep the majority of their views
  39. synchronous, and only have a select few running in async mode - but it is
  40. entirely your choice.
  41. Django's ORM, cache layer, and other pieces of code that do long-running
  42. network calls do not yet support async access. We expect to add support for
  43. them in upcoming releases. Async views are ideal, however, if you are doing a
  44. lot of API or HTTP calls inside your view, you can now natively do all those
  45. HTTP calls in parallel to considerably speed up your view's execution.
  46. Asynchronous support should be entirely backwards-compatible and we have tried
  47. to ensure that it has no speed regressions for your existing, synchronous code.
  48. It should have no noticeable effect on any existing Django projects.
  49. JSONField for all supported database backends
  50. ---------------------------------------------
  51. Django now includes the :class:`.models.JSONField` and
  52. :class:`forms.JSONField <django.forms.JSONField>` that can be used on all
  53. supported database backends. Both fields support the use of custom JSON
  54. encoders and decoders. The model field supports the introspection, lookups, and
  55. transforms that were previously PostgreSQL-only.
  56. If your project uses ``django.contrib.postgres.fields.JSONField``, plus the
  57. related form field and transforms, you should adjust to use the new fields,
  58. and generate and apply a database migration. For now, the old fields and
  59. transforms are left as a reference to the new ones and are :ref:`deprecated as
  60. of this release <deprecated-jsonfield>`.
  61. Minor features
  62. --------------
  63. :mod:`django.contrib.admin`
  64. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  65. * The new ``django.contrib.admin.EmptyFieldListFilter`` for
  66. :attr:`.ModelAdmin.list_filter` allows filtering on empty values (empty
  67. strings and nulls) in the admin changelist view.
  68. * Filters in the right sidebar of the admin changelist view now contains a link
  69. to clear all filters.
  70. * ``XRegExp`` is upgraded from version 2.0.0 to 3.2.0.
  71. * jQuery is upgraded from version 3.4.1 to 3.5.1.
  72. * Select2 library is upgraded from version 4.0.7 to 4.0.13.
  73. :mod:`django.contrib.admindocs`
  74. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  75. * ...
  76. :mod:`django.contrib.auth`
  77. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  78. * The default iteration count for the PBKDF2 password hasher is increased from
  79. 180,000 to 216,000.
  80. * Added the :setting:`PASSWORD_RESET_TIMEOUT` setting to define the number of
  81. seconds a password reset link is valid for. This is encouraged instead of
  82. deprecated ``PASSWORD_RESET_TIMEOUT_DAYS``, which will be removed in Django
  83. 4.0.
  84. * The password reset mechanism now uses the SHA-256 hashing algorithm. Support
  85. for tokens that use the old hashing algorithm remains until Django 4.0.
  86. * :meth:`.AbstractBaseUser.get_session_auth_hash` now uses the SHA-256 hashing
  87. algorithm. Support for user sessions that use the old hashing algorithm
  88. remains until Django 4.0.
  89. :mod:`django.contrib.contenttypes`
  90. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  91. * The new :option:`remove_stale_contenttypes --include-stale-apps` option
  92. allows removing stale content types from previously installed apps that have
  93. been removed from :setting:`INSTALLED_APPS`.
  94. :mod:`django.contrib.gis`
  95. ~~~~~~~~~~~~~~~~~~~~~~~~~
  96. * :lookup:`relate` lookup is now supported on MariaDB.
  97. * Added the :attr:`.LinearRing.is_counterclockwise` property.
  98. * :class:`~django.contrib.gis.db.models.functions.AsGeoJSON` is now supported
  99. on Oracle.
  100. * Added the :class:`~django.contrib.gis.db.models.functions.AsWKB` and
  101. :class:`~django.contrib.gis.db.models.functions.AsWKT` functions.
  102. * Added support for PostGIS 3.
  103. :mod:`django.contrib.humanize`
  104. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  105. * :tfilter:`intword` template filter now supports negative integers.
  106. :mod:`django.contrib.messages`
  107. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  108. * ...
  109. :mod:`django.contrib.postgres`
  110. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  111. * The new :class:`~django.contrib.postgres.indexes.BloomIndex` class allows
  112. creating ``bloom`` indexes in the database. The new
  113. :class:`~django.contrib.postgres.operations.BloomExtension` migration
  114. operation installs the ``bloom`` extension to add support for this index.
  115. * :meth:`~django.db.models.Model.get_FOO_display` now supports
  116. :class:`~django.contrib.postgres.fields.ArrayField` and
  117. :class:`~django.contrib.postgres.fields.RangeField`.
  118. * The new :lookup:`rangefield.lower_inc`, :lookup:`rangefield.lower_inf`,
  119. :lookup:`rangefield.upper_inc`, and :lookup:`rangefield.upper_inf` allows
  120. querying :class:`~django.contrib.postgres.fields.RangeField` by a bound type.
  121. * :lookup:`rangefield.contained_by` now supports
  122. :class:`~django.db.models.SmallAutoField`,
  123. :class:`~django.db.models.AutoField`,
  124. :class:`~django.db.models.BigAutoField`,
  125. :class:`~django.db.models.SmallIntegerField`, and
  126. :class:`~django.db.models.DecimalField`.
  127. * :class:`~django.contrib.postgres.search.SearchQuery` now supports
  128. ``'websearch'`` search type on PostgreSQL 11+.
  129. * :class:`SearchQuery.value <django.contrib.postgres.search.SearchQuery>` now
  130. supports query expressions.
  131. * The new :class:`~django.contrib.postgres.search.SearchHeadline` class allows
  132. highlighting search results.
  133. * :lookup:`search` lookup now supports query expressions.
  134. * The new ``cover_density`` parameter of
  135. :class:`~django.contrib.postgres.search.SearchRank` allows ranking by cover
  136. density.
  137. * The new ``normalization`` parameter of
  138. :class:`~django.contrib.postgres.search.SearchRank` allows rank
  139. normalization.
  140. * The new :attr:`.ExclusionConstraint.deferrable` attribute allows creating
  141. deferrable exclusion constraints.
  142. :mod:`django.contrib.redirects`
  143. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  144. * ...
  145. :mod:`django.contrib.sessions`
  146. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  147. * The :setting:`SESSION_COOKIE_SAMESITE` setting now allows ``'None'`` (string)
  148. value to explicitly state that the cookie is sent with all same-site and
  149. cross-site requests.
  150. :mod:`django.contrib.sitemaps`
  151. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  152. * ...
  153. :mod:`django.contrib.sites`
  154. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  155. * ...
  156. :mod:`django.contrib.staticfiles`
  157. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  158. * The :setting:`STATICFILES_DIRS` setting now supports :class:`pathlib.Path`.
  159. :mod:`django.contrib.syndication`
  160. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  161. * ...
  162. Cache
  163. ~~~~~
  164. * The :func:`~django.views.decorators.cache.cache_control` decorator and
  165. :func:`~django.utils.cache.patch_cache_control` method now support multiple
  166. field names in the ``no-cache`` directive for the ``Cache-Control`` header,
  167. according to :rfc:`7234#section-5.2.2.2`.
  168. * :meth:`~django.core.caches.cache.delete` now returns ``True`` if the key was
  169. successfully deleted, ``False`` otherwise.
  170. CSRF
  171. ~~~~
  172. * The :setting:`CSRF_COOKIE_SAMESITE` setting now allows ``'None'`` (string)
  173. value to explicitly state that the cookie is sent with all same-site and
  174. cross-site requests.
  175. Email
  176. ~~~~~
  177. * The :setting:`EMAIL_FILE_PATH` setting, used by the :ref:`file email backend
  178. <topic-email-file-backend>`, now supports :class:`pathlib.Path`.
  179. Error Reporting
  180. ~~~~~~~~~~~~~~~
  181. * :class:`django.views.debug.SafeExceptionReporterFilter` now filters sensitive
  182. values from ``request.META`` in exception reports.
  183. * The new :attr:`.SafeExceptionReporterFilter.cleansed_substitute` and
  184. :attr:`.SafeExceptionReporterFilter.hidden_settings` attributes allow
  185. customization of sensitive settings and ``request.META`` filtering in
  186. exception reports.
  187. * The technical 404 debug view now respects
  188. :setting:`DEFAULT_EXCEPTION_REPORTER_FILTER` when applying settings
  189. filtering.
  190. * The new :setting:`DEFAULT_EXCEPTION_REPORTER` allows providing a
  191. :class:`django.views.debug.ExceptionReporter` subclass to customize exception
  192. report generation. See :ref:`custom-error-reports` for details.
  193. File Storage
  194. ~~~~~~~~~~~~
  195. * ``FileSystemStorage.save()`` method now supports :class:`pathlib.Path`.
  196. * :class:`~django.db.models.FileField` and
  197. :class:`~django.db.models.ImageField` now accept a callable for ``storage``.
  198. This allows you to modify the used storage at runtime, selecting different
  199. storages for different environments, for example.
  200. File Uploads
  201. ~~~~~~~~~~~~
  202. * ...
  203. Forms
  204. ~~~~~
  205. * :class:`~django.forms.ModelChoiceIterator`, used by
  206. :class:`~django.forms.ModelChoiceField` and
  207. :class:`~django.forms.ModelMultipleChoiceField`, now uses
  208. :class:`~django.forms.ModelChoiceIteratorValue` that can be used by widgets
  209. to access model instances. See :ref:`iterating-relationship-choices` for
  210. details.
  211. * :class:`django.forms.DateTimeField` now accepts dates in a subset of ISO 8601
  212. datetime formats, including optional timezone (e.g. ``2019-10-10T06:47``,
  213. ``2019-10-10T06:47:23+04:00``, or ``2019-10-10T06:47:23Z``). Additionally, it
  214. now uses ``DATE_INPUT_FORMATS`` in addition to ``DATETIME_INPUT_FORMATS``
  215. when converting a field input to a ``datetime`` value.
  216. * :attr:`.MultiWidget.widgets` now accepts a dictionary which allows
  217. customizing subwidget ``name`` attributes.
  218. * The new :attr:`.BoundField.widget_type` property can be used to dynamically
  219. adjust form rendering based upon the widget type.
  220. Generic Views
  221. ~~~~~~~~~~~~~
  222. * ...
  223. Internationalization
  224. ~~~~~~~~~~~~~~~~~~~~
  225. * The :setting:`LANGUAGE_COOKIE_SAMESITE` setting now allows ``'None'``
  226. (string) value to explicitly state that the cookie is sent with all same-site
  227. and cross-site requests.
  228. * Added support and translations for the Algerian Arabic language.
  229. Logging
  230. ~~~~~~~
  231. * ...
  232. Management Commands
  233. ~~~~~~~~~~~~~~~~~~~
  234. * The new :option:`check --database` option allows specifying database aliases
  235. for running the ``database`` system checks. Previously these checks were
  236. enabled for all configured :setting:`DATABASES` by passing the ``database``
  237. tag to the command.
  238. * The new :option:`migrate --check` option makes the command exit with a
  239. non-zero status when unapplied migrations are detected.
  240. * The new ``returncode`` argument for
  241. :attr:`~django.core.management.CommandError` allows customizing the exit
  242. status for management commands.
  243. * The new :option:`dbshell -- ARGUMENTS <dbshell -->` option allows passing
  244. extra arguments to the command-line client for the database.
  245. * The :djadmin:`flush` and :djadmin:`sqlflush` commands now include SQL to
  246. reset sequences on SQLite.
  247. Migrations
  248. ~~~~~~~~~~
  249. * Migrations are now loaded also from directories without ``__init__.py``
  250. files.
  251. Models
  252. ~~~~~~
  253. * The new :class:`~django.db.models.functions.ExtractIsoWeekDay` function
  254. extracts ISO-8601 week days from :class:`~django.db.models.DateField` and
  255. :class:`~django.db.models.DateTimeField`, and the new :lookup:`iso_week_day`
  256. lookup allows querying by an ISO-8601 day of week.
  257. * :meth:`.QuerySet.explain` now supports:
  258. * ``TREE`` format on MySQL 8.0.16+,
  259. * ``analyze`` option on MySQL 8.0.18+ and MariaDB.
  260. * Added :class:`~django.db.models.PositiveBigIntegerField` which acts much like
  261. a :class:`~django.db.models.PositiveIntegerField` except that it only allows
  262. values under a certain (database-dependent) limit. Values from ``0`` to
  263. ``9223372036854775807`` are safe in all databases supported by Django.
  264. * The new :class:`~django.db.models.RESTRICT` option for
  265. :attr:`~django.db.models.ForeignKey.on_delete` argument of ``ForeignKey`` and
  266. ``OneToOneField`` emulates the behavior of the SQL constraint ``ON DELETE
  267. RESTRICT``.
  268. * :attr:`.CheckConstraint.check` now supports boolean expressions.
  269. * The :meth:`.RelatedManager.add`, :meth:`~.RelatedManager.create`, and
  270. :meth:`~.RelatedManager.set` methods now accept callables as values in the
  271. ``through_defaults`` argument.
  272. * The new ``is_dst`` parameter of the :meth:`.QuerySet.datetimes` determines
  273. the treatment of nonexistent and ambiguous datetimes.
  274. * The new :class:`~django.db.models.F` expression ``bitxor()`` method allows
  275. :ref:`bitwise XOR operation <using-f-expressions-in-filters>`.
  276. * :meth:`.QuerySet.bulk_create` now sets the primary key on objects when using
  277. MariaDB 10.5+.
  278. * The ``DatabaseOperations.sql_flush()`` method now generates more efficient
  279. SQL on MySQL by using ``DELETE`` instead of ``TRUNCATE`` statements for
  280. tables which don't require resetting sequences.
  281. * SQLite functions are now marked as :py:meth:`deterministic
  282. <sqlite3.Connection.create_function>` on Python 3.8+. This allows using them
  283. in check constraints and partial indexes.
  284. * The new :attr:`.UniqueConstraint.deferrable` attribute allows creating
  285. deferrable unique constraints.
  286. Pagination
  287. ~~~~~~~~~~
  288. * :class:`~django.core.paginator.Paginator` can now be iterated over to yield
  289. its pages.
  290. Requests and Responses
  291. ~~~~~~~~~~~~~~~~~~~~~~
  292. * If :setting:`ALLOWED_HOSTS` is empty and ``DEBUG=True``, subdomains of
  293. localhost are now allowed in the ``Host`` header, e.g. ``static.localhost``.
  294. * :meth:`.HttpResponse.set_cookie` and :meth:`.HttpResponse.set_signed_cookie`
  295. now allow using ``samesite='None'`` (string) to explicitly state that the
  296. cookie is sent with all same-site and cross-site requests.
  297. * The new :meth:`.HttpRequest.accepts` method returns whether the request
  298. accepts the given MIME type according to the ``Accept`` HTTP header.
  299. .. _whats-new-security-3.1:
  300. Security
  301. ~~~~~~~~
  302. * The :setting:`SECURE_REFERRER_POLICY` setting now defaults to
  303. ``'same-origin'``. With this configured,
  304. :class:`~django.middleware.security.SecurityMiddleware` sets the
  305. :ref:`referrer-policy` header to ``same-origin`` on all responses that do not
  306. already have it. This prevents the ``Referer`` header being sent to other
  307. origins. If you need the previous behavior, explicitly set
  308. :setting:`SECURE_REFERRER_POLICY` to ``None``.
  309. * The default :class:`django.core.signing.Signer` algorithm is changed to the
  310. SHA-256. Support for signatures made with the old SHA-1 algorithm remains
  311. until Django 4.0.
  312. Also, the new ``algorithm`` parameter of the
  313. :class:`~django.core.signing.Signer` allows customizing the hashing
  314. algorithm.
  315. Serialization
  316. ~~~~~~~~~~~~~
  317. * ...
  318. Signals
  319. ~~~~~~~
  320. * ...
  321. Templates
  322. ~~~~~~~~~
  323. * The renamed :ttag:`translate` and :ttag:`blocktranslate` template tags are
  324. introduced for internationalization in template code. The older :ttag:`trans`
  325. and :ttag:`blocktrans` template tags aliases continue to work, and will be
  326. retained for the foreseeable future.
  327. * The :ttag:`include` template tag now accepts iterables of template names.
  328. Tests
  329. ~~~~~
  330. * :class:`~django.test.SimpleTestCase` now implements the ``debug()`` method to
  331. allow running a test without collecting the result and catching exceptions.
  332. This can be used to support running tests under a debugger.
  333. * The new :setting:`MIGRATE <TEST_MIGRATE>` test database setting allows
  334. disabling of migrations during a test database creation.
  335. * Django test runner now supports a :option:`test --buffer` option to discard
  336. output for passing tests.
  337. * :class:`~django.test.runner.DiscoverRunner` now skips running the system
  338. checks on databases not :ref:`referenced by tests<testing-multi-db>`.
  339. * :class:`~django.test.TransactionTestCase` teardown is now faster on MySQL
  340. due to :djadmin:`flush` command improvements. As a side effect the latter
  341. doesn't automatically reset sequences on teardown anymore. Enable
  342. :attr:`.TransactionTestCase.reset_sequences` if your tests require this
  343. feature.
  344. URLs
  345. ~~~~
  346. * :ref:`Path converters <registering-custom-path-converters>` can now raise
  347. ``ValueError`` in ``to_url()`` to indicate no match when reversing URLs.
  348. Utilities
  349. ~~~~~~~~~
  350. * :func:`~django.utils.encoding.filepath_to_uri` now supports
  351. :class:`pathlib.Path`.
  352. * :func:`~django.utils.dateparse.parse_duration` now supports comma separators
  353. for decimal fractions in the ISO 8601 format.
  354. * :func:`~django.utils.dateparse.parse_datetime`,
  355. :func:`~django.utils.dateparse.parse_duration`, and
  356. :func:`~django.utils.dateparse.parse_time` now support comma separators for
  357. milliseconds.
  358. Validators
  359. ~~~~~~~~~~
  360. * ...
  361. Miscellaneous
  362. ~~~~~~~~~~~~~
  363. * The SQLite backend now supports :class:`pathlib.Path` for the ``NAME``
  364. setting.
  365. * The ``settings.py`` generated by the :djadmin:`startproject` command now uses
  366. :class:`pathlib.Path` instead of :mod:`os.path` for building filesystem
  367. paths.
  368. * The :setting:`TIME_ZONE <DATABASE-TIME_ZONE>` setting is now allowed on
  369. databases that support time zones.
  370. .. _backwards-incompatible-3.1:
  371. Backwards incompatible changes in 3.1
  372. =====================================
  373. Database backend API
  374. --------------------
  375. This section describes changes that may be needed in third-party database
  376. backends.
  377. * ``DatabaseOperations.fetch_returned_insert_columns()`` now requires an
  378. additional ``returning_params`` argument.
  379. * ``connection.timezone`` property is now ``'UTC'`` by default, or the
  380. :setting:`TIME_ZONE <DATABASE-TIME_ZONE>` when :setting:`USE_TZ` is ``True``
  381. on databases that support time zones. Previously, it was ``None`` on
  382. databases that support time zones.
  383. * ``connection._nodb_connection`` property is changed to the
  384. ``connection._nodb_cursor()`` method and now returns a context manager that
  385. yields a cursor and automatically closes the cursor and connection upon
  386. exiting the ``with`` statement.
  387. * ``DatabaseClient.runshell()`` now requires an additional ``parameters``
  388. argument as a list of extra arguments to pass on to the command-line client.
  389. * The ``sequences`` positional argument of ``DatabaseOperations.sql_flush()``
  390. is replaced by the boolean keyword-only argument ``reset_sequences``. If
  391. ``True``, the sequences of the truncated tables will be reset.
  392. * The ``allow_cascade`` argument of ``DatabaseOperations.sql_flush()`` is now a
  393. keyword-only argument.
  394. * The ``using`` positional argument of
  395. ``DatabaseOperations.execute_sql_flush()`` is removed. The method now uses
  396. the database of the called instance.
  397. * Third-party database backends must implement support for ``JSONField`` or set
  398. ``DatabaseFeatures.supports_json_field`` to ``False``. If storing primitives
  399. is not supported, set ``DatabaseFeatures.supports_primitives_in_json_field``
  400. to ``False``. If there is a true datatype for JSON, set
  401. ``DatabaseFeatures.has_native_json_field`` to ``True``.
  402. * Third party database backends must implement introspection for ``JSONField``
  403. or set ``can_introspect_json_field`` to ``False``.
  404. Dropped support for MariaDB 10.1
  405. --------------------------------
  406. Upstream support for MariaDB 10.1 ends in October 2020. Django 3.1 supports
  407. MariaDB 10.2 and higher.
  408. ``contrib.admin`` browser support
  409. ---------------------------------
  410. The admin no longer supports the legacy Internet Explorer browser. See
  411. :ref:`the admin FAQ <admin-browser-support>` for details on supported browsers.
  412. :attr:`AbstractUser.first_name <django.contrib.auth.models.User.first_name>` ``max_length`` increased to 150
  413. ------------------------------------------------------------------------------------------------------------
  414. A migration for :attr:`django.contrib.auth.models.User.first_name` is included.
  415. If you have a custom user model inheriting from ``AbstractUser``, you'll need
  416. to generate and apply a database migration for your user model.
  417. If you want to preserve the 30 character limit for first names, use a custom
  418. form::
  419. from django import forms
  420. from django.contrib.auth.forms import UserChangeForm
  421. class MyUserChangeForm(UserChangeForm):
  422. first_name = forms.CharField(max_length=30, required=False)
  423. If you wish to keep this restriction in the admin when editing users, set
  424. ``UserAdmin.form`` to use this form::
  425. from django.contrib.auth.admin import UserAdmin
  426. from django.contrib.auth.models import User
  427. class MyUserAdmin(UserAdmin):
  428. form = MyUserChangeForm
  429. admin.site.unregister(User)
  430. admin.site.register(User, MyUserAdmin)
  431. Miscellaneous
  432. -------------
  433. * The cache keys used by :ttag:`cache` and generated by
  434. :func:`~django.core.cache.utils.make_template_fragment_key` are different
  435. from the keys generated by older versions of Django. After upgrading to
  436. Django 3.1, the first request to any previously cached template fragment will
  437. be a cache miss.
  438. * The logic behind the decision to return a redirection fallback or a 204 HTTP
  439. response from the :func:`~django.views.i18n.set_language` view is now based
  440. on the ``Accept`` HTTP header instead of the ``X-Requested-With`` HTTP header
  441. presence.
  442. * The compatibility imports of ``django.core.exceptions.EmptyResultSet`` in
  443. ``django.db.models.query``, ``django.db.models.sql``, and
  444. ``django.db.models.sql.datastructures`` are removed.
  445. * The compatibility import of ``django.core.exceptions.FieldDoesNotExist`` in
  446. ``django.db.models.fields`` is removed.
  447. * The compatibility imports of ``django.forms.utils.pretty_name()`` and
  448. ``django.forms.boundfield.BoundField`` in ``django.forms.forms`` are removed.
  449. * The compatibility imports of ``Context``, ``ContextPopException``, and
  450. ``RequestContext`` in ``django.template.base`` are removed.
  451. * The compatibility import of
  452. ``django.contrib.admin.helpers.ACTION_CHECKBOX_NAME`` in
  453. ``django.contrib.admin`` is removed.
  454. * The :setting:`STATIC_URL` and :setting:`MEDIA_URL` settings set to relative
  455. paths are now prefixed by the server-provided value of ``SCRIPT_NAME`` (or
  456. ``/`` if not set). This change should not affect settings set to valid URLs
  457. or absolute paths.
  458. * :class:`~django.middleware.http.ConditionalGetMiddleware` no longer adds the
  459. ``ETag`` header to responses with an empty
  460. :attr:`~django.http.HttpResponse.content`.
  461. * ``django.utils.decorators.classproperty()`` decorator is made public and
  462. moved to :class:`django.utils.functional.classproperty()`.
  463. * :tfilter:`floatformat` template filter now outputs (positive) ``0`` for
  464. negative numbers which round to zero.
  465. * :attr:`Meta.ordering <django.db.models.Options.ordering>` and
  466. :attr:`Meta.unique_together <django.db.models.Options.unique_together>`
  467. options on models in ``django.contrib`` modules that were formerly tuples are
  468. now lists.
  469. * The admin calendar widget now handles two-digit years according to the Open
  470. Group Specification, i.e. values between 69 and 99 are mapped to the previous
  471. century, and values between 0 and 68 are mapped to the current century.
  472. * Date-only formats are removed from the default list for
  473. :setting:`DATETIME_INPUT_FORMATS`.
  474. * The :class:`~django.forms.FileInput` widget no longer renders with the
  475. ``required`` HTML attribute when initial data exists.
  476. * The undocumented ``django.views.debug.ExceptionReporterFilter`` class is
  477. removed. As per the :ref:`custom-error-reports` documentation, classes to be
  478. used with :setting:`DEFAULT_EXCEPTION_REPORTER_FILTER` needs to inherit from
  479. :class:`django.views.debug.SafeExceptionReporterFilter`.
  480. * The cache timeout set by :func:`~django.views.decorators.cache.cache_page`
  481. decorator now takes precedence over the ``max-age`` directive from the
  482. ``Cache-Control`` header.
  483. * Providing a non-local remote field in the :attr:`.ForeignKey.to_field`
  484. argument now raises :class:`~django.core.exceptions.FieldError`.
  485. * :setting:`SECURE_REFERRER_POLICY` now defaults to ``'same-origin'``. See the
  486. *What's New* :ref:`Security section <whats-new-security-3.1>` above for more
  487. details.
  488. * :djadmin:`check` management command now runs the ``database`` system checks
  489. only for database aliases specified using :option:`check --database` option.
  490. * :djadmin:`migrate` management command now runs the ``database`` system checks
  491. only for a database to migrate.
  492. * The admin CSS classes ``row1`` and ``row2`` are removed in favor of
  493. ``:nth-child(odd)`` and ``:nth-child(even)`` pseudo-classes.
  494. * The :func:`~django.contrib.auth.hashers.make_password` now requires its
  495. argument to be a string or bytes. Other types should be explicitly cast to
  496. one of these.
  497. * The undocumented ``version`` parameter to the
  498. :class:`~django.contrib.gis.db.models.functions.AsKML` function is removed.
  499. * :ref:`JSON and YAML serializers <serialization-formats>`, used by
  500. :djadmin:`dumpdata`, now dump all data with Unicode by default. If you need
  501. the previous behavior, pass ``ensure_ascii=True`` to JSON serializer, or
  502. ``allow_unicode=False`` to YAML serializer.
  503. * The auto-reloader no longer monitors changes in built-in Django translation
  504. files.
  505. * The minimum supported version of ``mysqlclient`` is increased from 1.3.13 to
  506. 1.4.0.
  507. * The undocumented ``django.contrib.postgres.forms.InvalidJSONInput`` and
  508. ``django.contrib.postgres.forms.JSONString`` are moved to
  509. ``django.forms.fields``.
  510. * The undocumented ``django.contrib.postgres.fields.jsonb.JsonAdapter`` class
  511. is removed.
  512. .. _deprecated-features-3.1:
  513. Features deprecated in 3.1
  514. ==========================
  515. .. _deprecated-jsonfield:
  516. PostgreSQL ``JSONField``
  517. ------------------------
  518. ``django.contrib.postgres.fields.JSONField`` and
  519. ``django.contrib.postgres.forms.JSONField`` are deprecated in favor of
  520. :class:`.models.JSONField` and
  521. :class:`forms.JSONField <django.forms.JSONField>`.
  522. The undocumented ``django.contrib.postgres.fields.jsonb.KeyTransform`` and
  523. ``django.contrib.postgres.fields.jsonb.KeyTextTransform`` are also deprecated
  524. in favor of the transforms in ``django.db.models.fields.json``.
  525. The new ``JSONField``\s, ``KeyTransform``, and ``KeyTextTransform`` can be used
  526. on all supported database backends.
  527. Miscellaneous
  528. -------------
  529. * ``PASSWORD_RESET_TIMEOUT_DAYS`` setting is deprecated in favor of
  530. :setting:`PASSWORD_RESET_TIMEOUT`.
  531. * The undocumented usage of the :lookup:`isnull` lookup with non-boolean values
  532. as the right-hand side is deprecated, use ``True`` or ``False`` instead.
  533. * The barely documented ``django.db.models.query_utils.InvalidQuery`` exception
  534. class is deprecated in favor of
  535. :class:`~django.core.exceptions.FieldDoesNotExist` and
  536. :class:`~django.core.exceptions.FieldError`.
  537. * The ``django-admin.py`` entry point is deprecated in favor of
  538. ``django-admin``.
  539. * The ``HttpRequest.is_ajax()`` method is deprecated as it relied on a
  540. jQuery-specific way of signifying AJAX calls, while current usage tends to
  541. use the JavaScript `Fetch API
  542. <https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API>`_. Depending on
  543. your use case, you can either write your own AJAX detection method, or use
  544. the new :meth:`.HttpRequest.accepts` method if your code depends on the
  545. client ``Accept`` HTTP header.
  546. If you are writing your own AJAX detection method, ``request.is_ajax()`` can
  547. be reproduced exactly as
  548. ``request.headers.get('x-requested-with') == 'XMLHttpRequest'``.
  549. * Passing ``None`` as the first argument to
  550. ``django.utils.deprecation.MiddlewareMixin.__init__()`` is deprecated.
  551. * The encoding format of cookies values used by
  552. :class:`~django.contrib.messages.storage.cookie.CookieStorage` is different
  553. from the format generated by older versions of Django. Support for the old
  554. format remains until Django 4.0.
  555. * The encoding format of sessions is different from the format generated by
  556. older versions of Django. Support for the old format remains until Django
  557. 4.0.
  558. * The purely documentational ``providing_args`` argument for
  559. :class:`~django.dispatch.Signal` is deprecated. If you rely on this
  560. argument as documentation, you can move the text to a code comment or
  561. docstring.
  562. * Calling ``django.utils.crypto.get_random_string()`` without a ``length``
  563. argument is deprecated.
  564. * The ``list`` message for :class:`~django.forms.ModelMultipleChoiceField` is
  565. deprecated in favor of ``invalid_list``.
  566. * The passing of URL kwargs directly to the context by
  567. :class:`~django.views.generic.base.TemplateView` is deprecated. Reference
  568. them in the template with ``view.kwargs`` instead.
  569. * Passing raw column aliases to :meth:`.QuerySet.order_by` is deprecated. The
  570. same result can be achieved by passing aliases in a
  571. :class:`~django.db.models.expressions.RawSQL` instead beforehand.
  572. * The ``NullBooleanField`` model field is deprecated in favor of
  573. ``BooleanField(null=True)``.
  574. * ``django.conf.urls.url()`` alias of :func:`django.urls.re_path` is
  575. deprecated.
  576. * The ``{% ifequal %}`` and ``{% ifnotequal %}`` template tags are deprecated
  577. in favor of :ttag:`{% if %}<if>`. ``{% if %}`` covers all use cases, but if
  578. you need to continue using these tags, they can be extracted from Django to a
  579. module and included as a built-in tag in the :class:`'builtins'
  580. <django.template.backends.django.DjangoTemplates>` option in
  581. :setting:`OPTIONS <TEMPLATES-OPTIONS>`.
  582. .. _removed-features-3.1:
  583. Features removed in 3.1
  584. =======================
  585. These features have reached the end of their deprecation cycle and are removed
  586. in Django 3.1.
  587. See :ref:`deprecated-features-2.2` for details on these changes, including how
  588. to remove usage of these features.
  589. * ``django.utils.timezone.FixedOffset`` is removed.
  590. * ``django.core.paginator.QuerySetPaginator`` is removed.
  591. * A model's ``Meta.ordering`` doesn't affect ``GROUP BY`` queries.
  592. * ``django.contrib.postgres.fields.FloatRangeField`` and
  593. ``django.contrib.postgres.forms.FloatRangeField`` are removed.
  594. * The ``FILE_CHARSET`` setting is removed.
  595. * ``django.contrib.staticfiles.storage.CachedStaticFilesStorage`` is removed.
  596. * The ``RemoteUserBackend.configure_user()`` method requires ``request`` as the
  597. first positional argument.
  598. * Support for ``SimpleTestCase.allow_database_queries`` and
  599. ``TransactionTestCase.multi_db`` is removed.