1. ========================
    
  2. Django 4.0 release notes
    
  3. ========================
    
  4. 
    
  5. *December 7, 2021*
    
  6. 
    
  7. Welcome to Django 4.0!
    
  8. 
    
  9. These release notes cover the :ref:`new features <whats-new-4.0>`, as well as
    
  10. some :ref:`backwards incompatible changes <backwards-incompatible-4.0>` you'll
    
  11. want to be aware of when upgrading from Django 3.2 or earlier. We've
    
  12. :ref:`begun the deprecation process for some features
    
  13. <deprecated-features-4.0>`.
    
  14. 
    
  15. See the :doc:`/howto/upgrade-version` guide if you're updating an existing
    
  16. project.
    
  17. 
    
  18. Python compatibility
    
  19. ====================
    
  20. 
    
  21. Django 4.0 supports Python 3.8, 3.9, and 3.10. We **highly recommend** and only
    
  22. officially support the latest release of each series.
    
  23. 
    
  24. The Django 3.2.x series is the last to support Python 3.6 and 3.7.
    
  25. 
    
  26. .. _whats-new-4.0:
    
  27. 
    
  28. What's new in Django 4.0
    
  29. ========================
    
  30. 
    
  31. ``zoneinfo`` default timezone implementation
    
  32. --------------------------------------------
    
  33. 
    
  34. The Python standard library's :mod:`zoneinfo` is now the default timezone
    
  35. implementation in Django.
    
  36. 
    
  37. This is the next step in the migration from using ``pytz`` to using
    
  38. :mod:`zoneinfo`. Django 3.2 allowed the use of non-``pytz`` time zones. Django
    
  39. 4.0 makes ``zoneinfo`` the default implementation. Support for ``pytz`` is now
    
  40. deprecated and will be removed in Django 5.0.
    
  41. 
    
  42. :mod:`zoneinfo` is part of the Python standard library from Python 3.9. The
    
  43. ``backports.zoneinfo`` package is automatically installed alongside Django if
    
  44. you are using Python 3.8.
    
  45. 
    
  46. The move to ``zoneinfo`` should be largely transparent. Selection of the
    
  47. current timezone, conversion of datetime instances to the current timezone in
    
  48. forms and templates, as well as operations on aware datetimes in UTC are
    
  49. unaffected.
    
  50. 
    
  51. However, if you are working with non-UTC time zones, and using the ``pytz``
    
  52. ``normalize()`` and ``localize()`` APIs, possibly with the :setting:`TIME_ZONE
    
  53. <DATABASE-TIME_ZONE>` setting, you will need to audit your code, since ``pytz``
    
  54. and ``zoneinfo`` are not entirely equivalent.
    
  55. 
    
  56. To give time for such an audit, the transitional :setting:`USE_DEPRECATED_PYTZ`
    
  57. setting allows continued use of ``pytz`` during the 4.x release cycle. This
    
  58. setting will be removed in Django 5.0.
    
  59. 
    
  60. In addition, a `pytz_deprecation_shim`_ package, created by the ``zoneinfo``
    
  61. author, can be used to assist with the migration from ``pytz``. This package
    
  62. provides shims to help you safely remove ``pytz``, and has a detailed
    
  63. `migration guide`_ showing how to move to the new ``zoneinfo`` APIs.
    
  64. 
    
  65. Using `pytz_deprecation_shim`_ and the :setting:`USE_DEPRECATED_PYTZ`
    
  66. transitional setting is recommended if you need a gradual update path.
    
  67. 
    
  68. .. _pytz_deprecation_shim: https://pytz-deprecation-shim.readthedocs.io/en/latest/index.html
    
  69. .. _migration guide: https://pytz-deprecation-shim.readthedocs.io/en/latest/migration.html
    
  70. 
    
  71. Functional unique constraints
    
  72. -----------------------------
    
  73. 
    
  74. The new :attr:`*expressions <django.db.models.UniqueConstraint.expressions>`
    
  75. positional argument of
    
  76. :class:`UniqueConstraint() <django.db.models.UniqueConstraint>` enables
    
  77. creating functional unique constraints on expressions and database functions.
    
  78. For example::
    
  79. 
    
  80.     from django.db import models
    
  81.     from django.db.models import UniqueConstraint
    
  82.     from django.db.models.functions import Lower
    
  83. 
    
  84. 
    
  85.     class MyModel(models.Model):
    
  86.         first_name = models.CharField(max_length=255)
    
  87.         last_name = models.CharField(max_length=255)
    
  88. 
    
  89.         class Meta:
    
  90.             constraints = [
    
  91.                 UniqueConstraint(
    
  92.                     Lower('first_name'),
    
  93.                     Lower('last_name').desc(),
    
  94.                     name='first_last_name_unique',
    
  95.                 ),
    
  96.             ]
    
  97. 
    
  98. Functional unique constraints are added to models using the
    
  99. :attr:`Meta.constraints <django.db.models.Options.constraints>` option.
    
  100. 
    
  101. ``scrypt`` password hasher
    
  102. --------------------------
    
  103. 
    
  104. The new :ref:`scrypt password hasher <scrypt-usage>` is more secure and
    
  105. recommended over PBKDF2. However, it's not the default as it requires OpenSSL
    
  106. 1.1+ and more memory.
    
  107. 
    
  108. Redis cache backend
    
  109. -------------------
    
  110. 
    
  111. The new ``django.core.cache.backends.redis.RedisCache`` cache backend provides
    
  112. built-in support for caching with Redis. `redis-py`_ 3.0.0 or higher is
    
  113. required. For more details, see the :ref:`documentation on caching with Redis
    
  114. in Django <redis>`.
    
  115. 
    
  116. .. _`redis-py`: https://pypi.org/project/redis/
    
  117. 
    
  118. Template based form rendering
    
  119. -----------------------------
    
  120. 
    
  121. :class:`Forms <django.forms.Form>`, :doc:`Formsets </topics/forms/formsets>`,
    
  122. and :class:`~django.forms.ErrorList` are now rendered using the template engine
    
  123. to enhance customization. See the new :meth:`~django.forms.Form.render`,
    
  124. :meth:`~django.forms.Form.get_context`, and
    
  125. :attr:`~django.forms.Form.template_name` for ``Form`` and
    
  126. :ref:`formset rendering <formset-rendering>` for ``Formset``.
    
  127. 
    
  128. Minor features
    
  129. --------------
    
  130. 
    
  131. :mod:`django.contrib.admin`
    
  132. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
  133. 
    
  134. * The ``admin/base.html`` template now has a new block ``header`` which
    
  135.   contains the admin site header.
    
  136. 
    
  137. * The new :meth:`.ModelAdmin.get_formset_kwargs` method allows customizing the
    
  138.   keyword arguments passed to the constructor of a formset.
    
  139. 
    
  140. * The navigation sidebar now has a quick filter toolbar.
    
  141. 
    
  142. * The new context variable ``model`` which contains the model class for each
    
  143.   model is added to the :meth:`.AdminSite.each_context` method.
    
  144. 
    
  145. * The new :attr:`.ModelAdmin.search_help_text` attribute allows specifying a
    
  146.   descriptive text for the search box.
    
  147. 
    
  148. * The :attr:`.InlineModelAdmin.verbose_name_plural` attribute now fallbacks to
    
  149.   the :attr:`.InlineModelAdmin.verbose_name` + ``'s'``.
    
  150. 
    
  151. * jQuery is upgraded from version 3.5.1 to 3.6.0.
    
  152. 
    
  153. :mod:`django.contrib.admindocs`
    
  154. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
  155. 
    
  156. * The admindocs now allows esoteric setups where :setting:`ROOT_URLCONF` is not
    
  157.   a string.
    
  158. 
    
  159. * The model section of the ``admindocs`` now shows cached properties.
    
  160. 
    
  161. :mod:`django.contrib.auth`
    
  162. ~~~~~~~~~~~~~~~~~~~~~~~~~~
    
  163. 
    
  164. * The default iteration count for the PBKDF2 password hasher is increased from
    
  165.   260,000 to 320,000.
    
  166. 
    
  167. * The new
    
  168.   :attr:`LoginView.next_page <django.contrib.auth.views.LoginView.next_page>`
    
  169.   attribute and
    
  170.   :meth:`~django.contrib.auth.views.LoginView.get_default_redirect_url` method
    
  171.   allow customizing the redirect after login.
    
  172. 
    
  173. :mod:`django.contrib.gis`
    
  174. ~~~~~~~~~~~~~~~~~~~~~~~~~
    
  175. 
    
  176. * Added support for SpatiaLite 5.
    
  177. 
    
  178. * :class:`~django.contrib.gis.gdal.GDALRaster` now allows creating rasters in
    
  179.   any GDAL virtual filesystem.
    
  180. 
    
  181. * The new :class:`~django.contrib.gis.admin.GISModelAdmin` class allows
    
  182.   customizing the widget used for ``GeometryField``. This is encouraged instead
    
  183.   of deprecated ``GeoModelAdmin`` and ``OSMGeoAdmin``.
    
  184. 
    
  185. :mod:`django.contrib.postgres`
    
  186. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
  187. 
    
  188. * The PostgreSQL backend now supports connecting by a service name. See
    
  189.   :ref:`postgresql-connection-settings` for more details.
    
  190. 
    
  191. * The new :class:`~django.contrib.postgres.operations.AddConstraintNotValid`
    
  192.   operation allows creating check constraints on PostgreSQL without verifying
    
  193.   that all existing rows satisfy the new constraint.
    
  194. 
    
  195. * The new :class:`~django.contrib.postgres.operations.ValidateConstraint`
    
  196.   operation allows validating check constraints which were created using
    
  197.   :class:`~django.contrib.postgres.operations.AddConstraintNotValid` on
    
  198.   PostgreSQL.
    
  199. 
    
  200. * The new
    
  201.   :class:`ArraySubquery() <django.contrib.postgres.expressions.ArraySubquery>`
    
  202.   expression allows using subqueries to construct lists of values on
    
  203.   PostgreSQL.
    
  204. 
    
  205. * The new :lookup:`trigram_word_similar` lookup, and the
    
  206.   :class:`TrigramWordDistance()
    
  207.   <django.contrib.postgres.search.TrigramWordDistance>` and
    
  208.   :class:`TrigramWordSimilarity()
    
  209.   <django.contrib.postgres.search.TrigramWordSimilarity>` expressions allow
    
  210.   using trigram word similarity.
    
  211. 
    
  212. :mod:`django.contrib.staticfiles`
    
  213. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
  214. 
    
  215. * :class:`~django.contrib.staticfiles.storage.ManifestStaticFilesStorage` now
    
  216.   replaces paths to JavaScript source map references with their hashed
    
  217.   counterparts.
    
  218. 
    
  219. * The new ``manifest_storage`` argument of
    
  220.   :class:`~django.contrib.staticfiles.storage.ManifestFilesMixin` and
    
  221.   :class:`~django.contrib.staticfiles.storage.ManifestStaticFilesStorage`
    
  222.   allows customizing the manifest file storage.
    
  223. 
    
  224. Cache
    
  225. ~~~~~
    
  226. 
    
  227. * The new async API for ``django.core.cache.backends.base.BaseCache`` begins
    
  228.   the process of making cache backends async-compatible. The new async methods
    
  229.   all have ``a`` prefixed names, e.g. ``aadd()``, ``aget()``, ``aset()``,
    
  230.   ``aget_or_set()``, or ``adelete_many()``.
    
  231. 
    
  232.   Going forward, the ``a`` prefix will be used for async variants of methods
    
  233.   generally.
    
  234. 
    
  235. CSRF
    
  236. ~~~~
    
  237. 
    
  238. * CSRF protection now consults the ``Origin`` header, if present. To facilitate
    
  239.   this, :ref:`some changes <csrf-trusted-origins-changes-4.0>` to the
    
  240.   :setting:`CSRF_TRUSTED_ORIGINS` setting are required.
    
  241. 
    
  242. Forms
    
  243. ~~~~~
    
  244. 
    
  245. * :class:`~django.forms.ModelChoiceField` now includes the provided value in
    
  246.   the ``params`` argument of a raised
    
  247.   :exc:`~django.core.exceptions.ValidationError` for the ``invalid_choice``
    
  248.   error message. This allows custom error messages to use the ``%(value)s``
    
  249.   placeholder.
    
  250. 
    
  251. * :class:`~django.forms.formsets.BaseFormSet` now renders non-form errors with
    
  252.   an additional class of ``nonform`` to help distinguish them from
    
  253.   form-specific errors.
    
  254. 
    
  255. * :class:`~django.forms.formsets.BaseFormSet` now allows customizing the widget
    
  256.   used when deleting forms via
    
  257.   :attr:`~django.forms.formsets.BaseFormSet.can_delete` by setting the
    
  258.   :attr:`~django.forms.formsets.BaseFormSet.deletion_widget` attribute or
    
  259.   overriding :meth:`~django.forms.formsets.BaseFormSet.get_deletion_widget`
    
  260.   method.
    
  261. 
    
  262. Internationalization
    
  263. ~~~~~~~~~~~~~~~~~~~~
    
  264. 
    
  265. * Added support and translations for the Malay language.
    
  266. 
    
  267. Generic Views
    
  268. ~~~~~~~~~~~~~
    
  269. 
    
  270. * :class:`~django.views.generic.edit.DeleteView` now uses
    
  271.   :class:`~django.views.generic.edit.FormMixin`, allowing you to provide a
    
  272.   :class:`~django.forms.Form` subclass, with a checkbox for example, to confirm
    
  273.   deletion. In addition, this allows ``DeleteView`` to function with
    
  274.   :class:`django.contrib.messages.views.SuccessMessageMixin`.
    
  275. 
    
  276.   In accordance with ``FormMixin``, object deletion for POST requests is
    
  277.   handled in ``form_valid()``. Custom delete logic in ``delete()`` handlers
    
  278.   should be moved to ``form_valid()``, or a shared helper method, as needed.
    
  279. 
    
  280. Logging
    
  281. ~~~~~~~
    
  282. 
    
  283. * The alias of the database used in an SQL call is now passed as extra context
    
  284.   along with each message to the :ref:`django-db-logger` logger.
    
  285. 
    
  286. Management Commands
    
  287. ~~~~~~~~~~~~~~~~~~~
    
  288. 
    
  289. * The :djadmin:`runserver` management command now supports the
    
  290.   :option:`--skip-checks` option.
    
  291. 
    
  292. * On PostgreSQL, :djadmin:`dbshell` now supports specifying a password file.
    
  293. 
    
  294. * The :djadmin:`shell` command now respects :py:data:`sys.__interactivehook__`
    
  295.   at startup. This allows loading shell history between interactive sessions.
    
  296.   As a consequence, ``readline`` is no longer loaded if running in *isolated*
    
  297.   mode.
    
  298. 
    
  299. * The new :attr:`BaseCommand.suppressed_base_arguments
    
  300.   <django.core.management.BaseCommand.suppressed_base_arguments>` attribute
    
  301.   allows suppressing unsupported default command options in the help output.
    
  302. 
    
  303. * The new :option:`startapp --exclude` and :option:`startproject --exclude`
    
  304.   options allow excluding directories from the template.
    
  305. 
    
  306. Models
    
  307. ~~~~~~
    
  308. 
    
  309. * New :meth:`QuerySet.contains(obj) <.QuerySet.contains>` method returns
    
  310.   whether the queryset contains the given object. This tries to perform the
    
  311.   query in the simplest and fastest way possible.
    
  312. 
    
  313. * The new ``precision`` argument of the
    
  314.   :class:`Round() <django.db.models.functions.Round>` database function allows
    
  315.   specifying the number of decimal places after rounding.
    
  316. 
    
  317. * :meth:`.QuerySet.bulk_create` now sets the primary key on objects when using
    
  318.   SQLite 3.35+.
    
  319. 
    
  320. * :class:`~django.db.models.DurationField` now supports multiplying and
    
  321.   dividing by scalar values on SQLite.
    
  322. 
    
  323. * :meth:`.QuerySet.bulk_update` now returns the number of objects updated.
    
  324. 
    
  325. * The new :attr:`.Expression.empty_result_set_value` attribute allows
    
  326.   specifying a value to return when the function is used over an empty result
    
  327.   set.
    
  328. 
    
  329. * The ``skip_locked`` argument of :meth:`.QuerySet.select_for_update()` is now
    
  330.   allowed on MariaDB 10.6+.
    
  331. 
    
  332. * :class:`~django.db.models.Lookup` expressions may now be used in ``QuerySet``
    
  333.   annotations, aggregations, and directly in filters.
    
  334. 
    
  335. * The new :ref:`default <aggregate-default>` argument for built-in aggregates
    
  336.   allows specifying a value to be returned when the queryset (or grouping)
    
  337.   contains no entries, rather than ``None``.
    
  338. 
    
  339. Requests and Responses
    
  340. ~~~~~~~~~~~~~~~~~~~~~~
    
  341. 
    
  342. * The :class:`~django.middleware.security.SecurityMiddleware` now adds the
    
  343.   :ref:`Cross-Origin Opener Policy <cross-origin-opener-policy>` header with a
    
  344.   value of ``'same-origin'`` to prevent cross-origin popups from sharing the
    
  345.   same browsing context. You can prevent this header from being added by
    
  346.   setting the :setting:`SECURE_CROSS_ORIGIN_OPENER_POLICY` setting to ``None``.
    
  347. 
    
  348. Signals
    
  349. ~~~~~~~
    
  350. 
    
  351. * The new ``stdout`` argument for :func:`~django.db.models.signals.pre_migrate`
    
  352.   and :func:`~django.db.models.signals.post_migrate` signals allows redirecting
    
  353.   output to a stream-like object. It should be preferred over
    
  354.   :py:data:`sys.stdout` and :py:func:`print` when emitting verbose output in
    
  355.   order to allow proper capture when testing.
    
  356. 
    
  357. Templates
    
  358. ~~~~~~~~~
    
  359. 
    
  360. * :tfilter:`floatformat` template filter now allows using the ``u`` suffix to
    
  361.   force disabling localization.
    
  362. 
    
  363. Tests
    
  364. ~~~~~
    
  365. 
    
  366. * The new ``serialized_aliases`` argument of
    
  367.   :func:`django.test.utils.setup_databases` determines which
    
  368.   :setting:`DATABASES` aliases test databases should have their state
    
  369.   serialized to allow usage of the
    
  370.   :ref:`serialized_rollback <test-case-serialized-rollback>` feature.
    
  371. 
    
  372. * Django test runner now supports a :option:`--buffer <test --buffer>` option
    
  373.   with parallel tests.
    
  374. 
    
  375. * The new ``logger`` argument to :class:`~django.test.runner.DiscoverRunner`
    
  376.   allows a Python :py:ref:`logger <logger>` to be used for logging.
    
  377. 
    
  378. * The new :meth:`.DiscoverRunner.log` method provides a way to log messages
    
  379.   that uses the ``DiscoverRunner.logger``, or prints to the console if not set.
    
  380. 
    
  381. * Django test runner now supports a :option:`--shuffle <test --shuffle>` option
    
  382.   to execute tests in a random order.
    
  383. 
    
  384. * The :option:`test --parallel` option now supports the value ``auto`` to run
    
  385.   one test process for each processor core.
    
  386. 
    
  387. * :meth:`.TestCase.captureOnCommitCallbacks` now captures new callbacks added
    
  388.   while executing :func:`.transaction.on_commit` callbacks.
    
  389. 
    
  390. .. _backwards-incompatible-4.0:
    
  391. 
    
  392. Backwards incompatible changes in 4.0
    
  393. =====================================
    
  394. 
    
  395. Database backend API
    
  396. --------------------
    
  397. 
    
  398. This section describes changes that may be needed in third-party database
    
  399. backends.
    
  400. 
    
  401. * ``DatabaseOperations.year_lookup_bounds_for_date_field()`` and
    
  402.   ``year_lookup_bounds_for_datetime_field()`` methods now take the optional
    
  403.   ``iso_year`` argument in order to support bounds for ISO-8601 week-numbering
    
  404.   years.
    
  405. 
    
  406. * The second argument of ``DatabaseSchemaEditor._unique_sql()`` and
    
  407.   ``_create_unique_sql()`` methods is now ``fields`` instead of ``columns``.
    
  408. 
    
  409. :mod:`django.contrib.gis`
    
  410. -------------------------
    
  411. 
    
  412. * Support for PostGIS 2.3 is removed.
    
  413. 
    
  414. * Support for GDAL 2.0 and GEOS 3.5 is removed.
    
  415. 
    
  416. Dropped support for PostgreSQL 9.6
    
  417. ----------------------------------
    
  418. 
    
  419. Upstream support for PostgreSQL 9.6 ends in November 2021. Django 4.0 supports
    
  420. PostgreSQL 10 and higher.
    
  421. 
    
  422. Also, the minimum supported version of ``psycopg2`` is increased from 2.5.4 to
    
  423. 2.8.4, as ``psycopg2`` 2.8.4 is the first release to support Python 3.8.
    
  424. 
    
  425. Dropped support for Oracle 12.2 and 18c
    
  426. ---------------------------------------
    
  427. 
    
  428. Upstream support for Oracle 12.2 ends in March 2022 and for Oracle 18c it ends
    
  429. in June 2021. Django 3.2 will be supported until April 2024. Django 4.0
    
  430. officially supports Oracle 19c.
    
  431. 
    
  432. .. _csrf-trusted-origins-changes-4.0:
    
  433. 
    
  434. ``CSRF_TRUSTED_ORIGINS`` changes
    
  435. --------------------------------
    
  436. 
    
  437. Format change
    
  438. ~~~~~~~~~~~~~
    
  439. 
    
  440. Values in the :setting:`CSRF_TRUSTED_ORIGINS` setting must include the scheme
    
  441. (e.g. ``'http://'`` or ``'https://'``) instead of only the hostname.
    
  442. 
    
  443. Also, values that started with a dot, must now also include an asterisk before
    
  444. the dot. For example, change ``'.example.com'`` to ``'https://*.example.com'``.
    
  445. 
    
  446. A system check detects any required changes.
    
  447. 
    
  448. Configuring it may now be required
    
  449. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
  450. 
    
  451. As CSRF protection now consults the ``Origin`` header, you may need to set
    
  452. :setting:`CSRF_TRUSTED_ORIGINS`, particularly if you allow requests from
    
  453. subdomains by setting :setting:`CSRF_COOKIE_DOMAIN` (or
    
  454. :setting:`SESSION_COOKIE_DOMAIN` if :setting:`CSRF_USE_SESSIONS` is enabled) to
    
  455. a value starting with a dot.
    
  456. 
    
  457. ``SecurityMiddleware`` no longer sets the ``X-XSS-Protection`` header
    
  458. ---------------------------------------------------------------------
    
  459. 
    
  460. The :class:`~django.middleware.security.SecurityMiddleware` no longer sets the
    
  461. ``X-XSS-Protection`` header if the ``SECURE_BROWSER_XSS_FILTER`` setting is
    
  462. ``True``. The setting is removed.
    
  463. 
    
  464. Most modern browsers don't honor the ``X-XSS-Protection`` HTTP header. You can
    
  465. use Content-Security-Policy_ without allowing ``'unsafe-inline'`` scripts
    
  466. instead.
    
  467. 
    
  468. If you want to support legacy browsers and set the header, use this line in a
    
  469. custom middleware::
    
  470. 
    
  471.     response.headers.setdefault('X-XSS-Protection', '1; mode=block')
    
  472. 
    
  473. .. _Content-Security-Policy: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
    
  474. 
    
  475. Migrations autodetector changes
    
  476. -------------------------------
    
  477. 
    
  478. The migrations autodetector now uses model states instead of model classes.
    
  479. Also, migration operations for ``ForeignKey`` and ``ManyToManyField`` fields no
    
  480. longer specify attributes which were not passed to the fields during
    
  481. initialization.
    
  482. 
    
  483. As a side-effect, running ``makemigrations`` might generate no-op
    
  484. ``AlterField`` operations for ``ManyToManyField`` and ``ForeignKey`` fields in
    
  485. some cases.
    
  486. 
    
  487. ``DeleteView`` changes
    
  488. ----------------------
    
  489. 
    
  490. :class:`~django.views.generic.edit.DeleteView` now uses
    
  491. :class:`~django.views.generic.edit.FormMixin` to handle POST requests. As a
    
  492. consequence, any custom deletion logic in ``delete()`` handlers should be
    
  493. moved to ``form_valid()``, or a shared helper method, if required.
    
  494. 
    
  495. Table and column naming scheme changes on Oracle
    
  496. ------------------------------------------------
    
  497. 
    
  498. Django 4.0 inadvertently changed the table and column naming scheme on Oracle.
    
  499. This causes errors for models and fields with names longer than 30 characters.
    
  500. Unfortunately, renaming some Oracle tables and columns is required. Use the
    
  501. upgrade script in :ticket:`33789 <33789#comment:15>` to generate ``RENAME``
    
  502. statements to change naming scheme.
    
  503. 
    
  504. Miscellaneous
    
  505. -------------
    
  506. 
    
  507. * Support for ``cx_Oracle`` < 7.0 is removed.
    
  508. 
    
  509. * To allow serving a Django site on a subpath without changing the value of
    
  510.   :setting:`STATIC_URL`, the leading slash is removed from that setting (now
    
  511.   ``'static/'``) in the default :djadmin:`startproject` template.
    
  512. 
    
  513. * The :class:`~django.contrib.admin.AdminSite` method for the admin ``index``
    
  514.   view is no longer decorated with ``never_cache`` when accessed directly,
    
  515.   rather than via the recommended ``AdminSite.urls`` property, or
    
  516.   ``AdminSite.get_urls()`` method.
    
  517. 
    
  518. * Unsupported operations on a sliced queryset now raise ``TypeError`` instead
    
  519.   of ``AssertionError``.
    
  520. 
    
  521. * The undocumented ``django.test.runner.reorder_suite()`` function is renamed
    
  522.   to ``reorder_tests()``. It now accepts an iterable of tests rather than a
    
  523.   test suite, and returns an iterator of tests.
    
  524. 
    
  525. * Calling ``FileSystemStorage.delete()`` with an empty ``name`` now raises
    
  526.   ``ValueError`` instead of ``AssertionError``.
    
  527. 
    
  528. * Calling ``EmailMultiAlternatives.attach_alternative()`` or
    
  529.   ``EmailMessage.attach()`` with an invalid ``content`` or ``mimetype``
    
  530.   arguments now raise ``ValueError`` instead of ``AssertionError``.
    
  531. 
    
  532. * :meth:`~django.test.SimpleTestCase.assertHTMLEqual` no longer considers a
    
  533.   non-boolean attribute without a value equal to an attribute with the same
    
  534.   name and value.
    
  535. 
    
  536. * Tests that fail to load, for example due to syntax errors, now always match
    
  537.   when using :option:`test --tag`.
    
  538. 
    
  539. * The undocumented ``django.contrib.admin.utils.lookup_needs_distinct()``
    
  540.   function is renamed to ``lookup_spawns_duplicates()``.
    
  541. 
    
  542. * The undocumented ``HttpRequest.get_raw_uri()`` method is removed. The
    
  543.   :meth:`.HttpRequest.build_absolute_uri` method may be a suitable alternative.
    
  544. 
    
  545. * The ``object`` argument of undocumented ``ModelAdmin.log_addition()``,
    
  546.   ``log_change()``, and ``log_deletion()`` methods is renamed to ``obj``.
    
  547. 
    
  548. * :class:`~django.utils.feedgenerator.RssFeed`,
    
  549.   :class:`~django.utils.feedgenerator.Atom1Feed`, and their subclasses now emit
    
  550.   elements with no content as self-closing tags.
    
  551. 
    
  552. * ``NodeList.render()`` no longer casts the output of ``render()`` method for
    
  553.   individual nodes to a string. ``Node.render()`` should always return a string
    
  554.   as documented.
    
  555. 
    
  556. * The ``where_class`` property of ``django.db.models.sql.query.Query`` and the
    
  557.   ``where_class`` argument to the private ``get_extra_restriction()`` method of
    
  558.   ``ForeignObject`` and ``ForeignObjectRel`` are removed. If needed, initialize
    
  559.   ``django.db.models.sql.where.WhereNode`` instead.
    
  560. 
    
  561. * The ``filter_clause`` argument of the undocumented ``Query.add_filter()``
    
  562.   method is replaced by two positional arguments ``filter_lhs`` and
    
  563.   ``filter_rhs``.
    
  564. 
    
  565. * :class:`~django.middleware.csrf.CsrfViewMiddleware` now uses
    
  566.   ``request.META['CSRF_COOKIE_NEEDS_UPDATE']`` in place of
    
  567.   ``request.META['CSRF_COOKIE_USED']``, ``request.csrf_cookie_needs_reset``,
    
  568.   and ``response.csrf_cookie_set`` to track whether the CSRF cookie should be
    
  569.   sent. This is an undocumented, private API.
    
  570. 
    
  571. * The undocumented ``TRANSLATOR_COMMENT_MARK`` constant is moved from
    
  572.   ``django.template.base`` to ``django.utils.translation.template``.
    
  573. 
    
  574. * The ``real_apps`` argument of the undocumented
    
  575.   ``django.db.migrations.state.ProjectState.__init__()`` method must now be a
    
  576.   set if provided.
    
  577. 
    
  578. * :class:`~django.forms.RadioSelect` and
    
  579.   :class:`~django.forms.CheckboxSelectMultiple` widgets are now rendered in
    
  580.   ``<div>`` tags so they are announced more concisely by screen readers. If you
    
  581.   need the previous behavior, :ref:`override the widget template
    
  582.   <overriding-built-in-widget-templates>` with the appropriate template from
    
  583.   Django 3.2.
    
  584. 
    
  585. * The :tfilter:`floatformat` template filter no longer depends on the
    
  586.   ``USE_L10N`` setting and always returns localized output. Use the ``u``
    
  587.   suffix to disable localization.
    
  588. 
    
  589. * The default value of the ``USE_L10N`` setting is changed to ``True``. See the
    
  590.   :ref:`Localization section <use_l10n_deprecation>` above for more details.
    
  591. 
    
  592. * As part of the :ref:`move to zoneinfo <whats-new-4.0>`,
    
  593.   :attr:`django.utils.timezone.utc` is changed to alias
    
  594.   :attr:`datetime.timezone.utc`.
    
  595. 
    
  596. * The minimum supported version of ``asgiref`` is increased from 3.3.2 to
    
  597.   3.4.1.
    
  598. 
    
  599. .. _deprecated-features-4.0:
    
  600. 
    
  601. Features deprecated in 4.0
    
  602. ==========================
    
  603. 
    
  604. Use of ``pytz`` time zones
    
  605. --------------------------
    
  606. 
    
  607. As part of the :ref:`move to zoneinfo <whats-new-4.0>`, use of ``pytz`` time
    
  608. zones is deprecated.
    
  609. 
    
  610. Accordingly, the ``is_dst`` arguments to the following are also deprecated:
    
  611. 
    
  612. * :meth:`django.db.models.query.QuerySet.datetimes`
    
  613. * :func:`django.db.models.functions.Trunc`
    
  614. * :func:`django.db.models.functions.TruncSecond`
    
  615. * :func:`django.db.models.functions.TruncMinute`
    
  616. * :func:`django.db.models.functions.TruncHour`
    
  617. * :func:`django.db.models.functions.TruncDay`
    
  618. * :func:`django.db.models.functions.TruncWeek`
    
  619. * :func:`django.db.models.functions.TruncMonth`
    
  620. * :func:`django.db.models.functions.TruncQuarter`
    
  621. * :func:`django.db.models.functions.TruncYear`
    
  622. * :func:`django.utils.timezone.make_aware`
    
  623. 
    
  624. Support for use of ``pytz`` will be removed in Django 5.0.
    
  625. 
    
  626. Time zone support
    
  627. -----------------
    
  628. 
    
  629. In order to follow good practice, the default value of the :setting:`USE_TZ`
    
  630. setting will change from ``False`` to ``True``, and time zone support will be
    
  631. enabled by default, in Django 5.0.
    
  632. 
    
  633. Note that the default :file:`settings.py` file created by
    
  634. :djadmin:`django-admin startproject <startproject>` includes
    
  635. :setting:`USE_TZ = True <USE_TZ>` since Django 1.4.
    
  636. 
    
  637. You can set ``USE_TZ`` to ``False`` in your project settings before then to
    
  638. opt-out.
    
  639. 
    
  640. .. _use_l10n_deprecation:
    
  641. 
    
  642. Localization
    
  643. ------------
    
  644. 
    
  645. In order to follow good practice, the default value of the ``USE_L10N`` setting
    
  646. is changed from ``False`` to ``True``.
    
  647. 
    
  648. Moreover ``USE_L10N`` is deprecated as of this release. Starting with Django
    
  649. 5.0, by default, any date or number displayed by Django will be localized.
    
  650. 
    
  651. The :ttag:`{% localize %} <localize>` tag and the :tfilter:`localize`/
    
  652. :tfilter:`unlocalize` filters will still be honored by Django.
    
  653. 
    
  654. Miscellaneous
    
  655. -------------
    
  656. 
    
  657. * ``SERIALIZE`` test setting is deprecated as it can be inferred from the
    
  658.   :attr:`~django.test.TestCase.databases` with the
    
  659.   :ref:`serialized_rollback <test-case-serialized-rollback>` option enabled.
    
  660. 
    
  661. * The undocumented ``django.utils.baseconv`` module is deprecated.
    
  662. 
    
  663. * The undocumented ``django.utils.datetime_safe`` module is deprecated.
    
  664. 
    
  665. * The default sitemap protocol for sitemaps built outside the context of a
    
  666.   request will change from ``'http'`` to ``'https'`` in Django 5.0.
    
  667. 
    
  668. * The ``extra_tests`` argument for :meth:`.DiscoverRunner.build_suite` and
    
  669.   :meth:`.DiscoverRunner.run_tests` is deprecated.
    
  670. 
    
  671. * The :class:`~django.contrib.postgres.aggregates.ArrayAgg`,
    
  672.   :class:`~django.contrib.postgres.aggregates.JSONBAgg`, and
    
  673.   :class:`~django.contrib.postgres.aggregates.StringAgg` aggregates will return
    
  674.   ``None`` when there are no rows instead of ``[]``, ``[]``, and ``''``
    
  675.   respectively in Django 5.0. If you need the previous behavior, explicitly set
    
  676.   ``default`` to ``Value([])``, ``Value('[]')``, or ``Value('')``.
    
  677. 
    
  678. * The ``django.contrib.gis.admin.GeoModelAdmin`` and ``OSMGeoAdmin`` classes
    
  679.   are deprecated. Use :class:`~django.contrib.admin.ModelAdmin` and
    
  680.   :class:`~django.contrib.gis.admin.GISModelAdmin` instead.
    
  681. 
    
  682. * Since form rendering now uses the template engine, the undocumented
    
  683.   ``BaseForm._html_output()`` helper method is deprecated.
    
  684. 
    
  685. * The ability to return a ``str`` from ``ErrorList`` and ``ErrorDict`` is
    
  686.   deprecated. It is expected these methods return a ``SafeString``.
    
  687. 
    
  688. Features removed in 4.0
    
  689. =======================
    
  690. 
    
  691. These features have reached the end of their deprecation cycle and are removed
    
  692. in Django 4.0.
    
  693. 
    
  694. See :ref:`deprecated-features-3.0` for details on these changes, including how
    
  695. to remove usage of these features.
    
  696. 
    
  697. * ``django.utils.http.urlquote()``, ``urlquote_plus()``, ``urlunquote()``, and
    
  698.   ``urlunquote_plus()`` are removed.
    
  699. 
    
  700. * ``django.utils.encoding.force_text()`` and ``smart_text()`` are removed.
    
  701. 
    
  702. * ``django.utils.translation.ugettext()``, ``ugettext_lazy()``,
    
  703.   ``ugettext_noop()``, ``ungettext()``, and ``ungettext_lazy()`` are removed.
    
  704. 
    
  705. * ``django.views.i18n.set_language()`` doesn't set the user language in
    
  706.   ``request.session`` (key ``_language``).
    
  707. 
    
  708. * ``alias=None`` is required in the signature of
    
  709.   ``django.db.models.Expression.get_group_by_cols()`` subclasses.
    
  710. 
    
  711. * ``django.utils.text.unescape_entities()`` is removed.
    
  712. 
    
  713. * ``django.utils.http.is_safe_url()`` is removed.
    
  714. 
    
  715. See :ref:`deprecated-features-3.1` for details on these changes, including how
    
  716. to remove usage of these features.
    
  717. 
    
  718. * The ``PASSWORD_RESET_TIMEOUT_DAYS`` setting is removed.
    
  719. 
    
  720. * The :lookup:`isnull` lookup no longer allows using non-boolean values as the
    
  721.   right-hand side.
    
  722. 
    
  723. * The ``django.db.models.query_utils.InvalidQuery`` exception class is removed.
    
  724. 
    
  725. * The ``django-admin.py`` entry point is removed.
    
  726. 
    
  727. * The ``HttpRequest.is_ajax()`` method is removed.
    
  728. 
    
  729. * Support for the pre-Django 3.1 encoding format of cookies values used by
    
  730.   ``django.contrib.messages.storage.cookie.CookieStorage`` is removed.
    
  731. 
    
  732. * Support for the pre-Django 3.1 password reset tokens in the admin site (that
    
  733.   use the SHA-1 hashing algorithm) is removed.
    
  734. 
    
  735. * Support for the pre-Django 3.1 encoding format of sessions is removed.
    
  736. 
    
  737. * Support for the pre-Django 3.1 ``django.core.signing.Signer`` signatures
    
  738.   (encoded with the SHA-1 algorithm) is removed.
    
  739. 
    
  740. * Support for the pre-Django 3.1 ``django.core.signing.dumps()`` signatures
    
  741.   (encoded with the SHA-1 algorithm) in ``django.core.signing.loads()`` is
    
  742.   removed.
    
  743. 
    
  744. * Support for the pre-Django 3.1 user sessions (that use the SHA-1 algorithm)
    
  745.   is removed.
    
  746. 
    
  747. * The ``get_response`` argument for
    
  748.   ``django.utils.deprecation.MiddlewareMixin.__init__()`` is required and
    
  749.   doesn't accept ``None``.
    
  750. 
    
  751. * The ``providing_args`` argument for ``django.dispatch.Signal`` is removed.
    
  752. 
    
  753. * The ``length`` argument for ``django.utils.crypto.get_random_string()`` is
    
  754.   required.
    
  755. 
    
  756. * The ``list`` message for ``ModelMultipleChoiceField`` is removed.
    
  757. 
    
  758. * Support for passing raw column aliases to ``QuerySet.order_by()`` is removed.
    
  759. 
    
  760. * The ``NullBooleanField`` model field is removed, except for support in
    
  761.   historical migrations.
    
  762. 
    
  763. * ``django.conf.urls.url()`` is removed.
    
  764. 
    
  765. * The ``django.contrib.postgres.fields.JSONField`` model field is removed,
    
  766.   except for support in historical migrations.
    
  767. 
    
  768. * ``django.contrib.postgres.fields.jsonb.KeyTransform`` and
    
  769.   ``django.contrib.postgres.fields.jsonb.KeyTextTransform`` are removed.
    
  770. 
    
  771. * ``django.contrib.postgres.forms.JSONField`` is removed.
    
  772. 
    
  773. * The ``{% ifequal %}`` and ``{% ifnotequal %}`` template tags are removed.
    
  774. 
    
  775. * The ``DEFAULT_HASHING_ALGORITHM`` transitional setting is removed.