2.2.txt 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. ============================================
  2. Django 2.2 release notes - UNDER DEVELOPMENT
  3. ============================================
  4. *Expected April 2019*
  5. Welcome to Django 2.2!
  6. These release notes cover the :ref:`new features <whats-new-2.2>`, as well as
  7. some :ref:`backwards incompatible changes <backwards-incompatible-2.2>` you'll
  8. want to be aware of when upgrading from Django 2.1 or earlier. We've
  9. :ref:`begun the deprecation process for some features
  10. <deprecated-features-2.2>`.
  11. See the :doc:`/howto/upgrade-version` guide if you're updating an existing
  12. project.
  13. Django 2.2 is designated as a :term:`long-term support release`. It will
  14. receive security updates for at least three years after its release. Support
  15. for the previous LTS, Django 1.11, will end in April 2020.
  16. Python compatibility
  17. ====================
  18. Django 2.2 supports Python 3.5, 3.6, and 3.7. We **highly recommend** and only
  19. officially support the latest release of each series.
  20. .. _whats-new-2.2:
  21. What's new in Django 2.2
  22. ========================
  23. Constraints
  24. -----------
  25. The new :class:`~django.db.models.CheckConstraint` and
  26. :class:`~django.db.models.UniqueConstraint` classes enable adding custom
  27. database constraints. Constraints are added to models using the
  28. :attr:`Meta.constraints <django.db.models.Options.constraints>` option.
  29. Minor features
  30. --------------
  31. :mod:`django.contrib.admin`
  32. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  33. * Added a CSS class to the column headers of
  34. :class:`~django.contrib.admin.TabularInline`.
  35. :mod:`django.contrib.admindocs`
  36. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  37. * ...
  38. :mod:`django.contrib.auth`
  39. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  40. * ...
  41. :mod:`django.contrib.contenttypes`
  42. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  43. * ...
  44. :mod:`django.contrib.gis`
  45. ~~~~~~~~~~~~~~~~~~~~~~~~~
  46. * Added Oracle support for the
  47. :class:`~django.contrib.gis.db.models.functions.Envelope` function.
  48. * Added SpatiaLite support for the :lookup:`coveredby` and :lookup:`covers`
  49. lookups.
  50. :mod:`django.contrib.messages`
  51. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  52. * ...
  53. :mod:`django.contrib.postgres`
  54. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  55. * The new ``ordering`` argument for
  56. :class:`~django.contrib.postgres.aggregates.ArrayAgg` and
  57. :class:`~django.contrib.postgres.aggregates.StringAgg` determines the
  58. ordering of the aggregated elements.
  59. * The new :class:`~django.contrib.postgres.indexes.BTreeIndex`,
  60. :class:`~django.contrib.postgres.indexes.HashIndex` and
  61. :class:`~django.contrib.postgres.indexes.SpGistIndex` classes allow
  62. creating ``B-Tree``, ``hash``, and ``SP-GiST`` indexes in the database.
  63. * :class:`~django.contrib.postgres.indexes.BrinIndex` now has the
  64. ``autosummarize`` parameter.
  65. * The new ``search_type`` parameter of
  66. :class:`~django.contrib.postgres.search.SearchQuery` allows searching for
  67. a phrase or raw expression.
  68. :mod:`django.contrib.redirects`
  69. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  70. * ...
  71. :mod:`django.contrib.sessions`
  72. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  73. * ...
  74. :mod:`django.contrib.sitemaps`
  75. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  76. * ...
  77. :mod:`django.contrib.sites`
  78. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  79. * ...
  80. :mod:`django.contrib.staticfiles`
  81. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  82. * Added path matching to the :option:`collectstatic --ignore` option so that
  83. patterns like ``/vendor/*.js`` can be used.
  84. :mod:`django.contrib.syndication`
  85. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  86. * ...
  87. Cache
  88. ~~~~~
  89. * ...
  90. CSRF
  91. ~~~~
  92. * ...
  93. Database backends
  94. ~~~~~~~~~~~~~~~~~
  95. * Added result streaming for :meth:`.QuerySet.iterator` on SQLite.
  96. Email
  97. ~~~~~
  98. * ...
  99. File Storage
  100. ~~~~~~~~~~~~
  101. * ...
  102. File Uploads
  103. ~~~~~~~~~~~~
  104. * ...
  105. Forms
  106. ~~~~~
  107. * ...
  108. Generic Views
  109. ~~~~~~~~~~~~~
  110. * The new :meth:`View.setup <django.views.generic.base.View.setup>` hook
  111. initializes view attributes before calling
  112. :meth:`~django.views.generic.base.View.dispatch`. It allows mixins to setup
  113. instance attributes for reuse in child classes.
  114. Internationalization
  115. ~~~~~~~~~~~~~~~~~~~~
  116. * ...
  117. Management Commands
  118. ~~~~~~~~~~~~~~~~~~~
  119. * The new :option:`--force-color` option forces colorization of the command
  120. output.
  121. * :djadmin:`inspectdb` now creates models for foreign tables on PostgreSQL.
  122. * :option:`inspectdb --include-views` now creates models for materialized views
  123. on Oracle and PostgreSQL.
  124. * The new :option:`inspectdb --include-partitions` option allows creating
  125. models for partition tables on PostgreSQL. In older versions, models are
  126. created child tables instead the parent.
  127. * :djadmin:`inspectdb` now introspects :class:`~django.db.models.DurationField`
  128. for Oracle and PostgreSQL.
  129. * On Oracle, :djadmin:`dbshell` is wrapped with ``rlwrap``, if available.
  130. ``rlwrap`` provides a command history and editing of keyboard input.
  131. * The new :option:`makemigrations --no-header` option avoids writing header
  132. comments in generated migration file(s). This option is also available for
  133. :djadmin:`squashmigrations`.
  134. Migrations
  135. ~~~~~~~~~~
  136. * The new :option:`migrate --plan` option prints the list of migration
  137. operations that will be performed.
  138. * ``NoneType`` can now be serialized in migrations.
  139. Models
  140. ~~~~~~
  141. * Added support for PostgreSQL operator classes (:attr:`.Index.opclasses`).
  142. * Added support for partial indexes (:attr:`.Index.condition`).
  143. * Added many :ref:`math database functions <math-functions>`.
  144. * Setting the new ``ignore_conflicts`` parameter of
  145. :meth:`.QuerySet.bulk_create` to ``True`` tells the database to ignore
  146. failure to insert rows that fail uniqueness constraints or other checks.
  147. * The new :class:`~django.db.models.functions.ExtractIsoYear` function extracts
  148. ISO-8601 week-numbering years from :class:`~django.db.models.DateField` and
  149. :class:`~django.db.models.DateTimeField`, and the new :lookup:`iso_year`
  150. lookup allows querying by an ISO-8601 week-numbering year.
  151. * The new :meth:`.QuerySet.bulk_update` method allows efficiently updating
  152. specific fields on multiple model instances.
  153. * Django no longer always starts a transaction when a single query is being
  154. performed, such as ``Model.save()``, ``QuerySet.update()``, and
  155. ``Model.delete()``. This improves the performance of autocommit by reducing
  156. the number of database round trips.
  157. Requests and Responses
  158. ~~~~~~~~~~~~~~~~~~~~~~
  159. * ...
  160. Serialization
  161. ~~~~~~~~~~~~~
  162. * You can now deserialize data using natural keys containing :ref:`forward
  163. references <natural-keys-and-forward-references>` by passing
  164. ``handle_forward_references=True`` to ``serializers.deserialize()``.
  165. Additionally, :djadmin:`loaddata` handles forward references automatically.
  166. Signals
  167. ~~~~~~~
  168. * ...
  169. Templates
  170. ~~~~~~~~~
  171. * ...
  172. Tests
  173. ~~~~~
  174. * The new :meth:`.SimpleTestCase.assertURLEqual` assertion checks for a given
  175. URL, ignoring the ordering of the query string.
  176. :meth:`~.SimpleTestCase.assertRedirects` uses the new assertion.
  177. * The test :class:`~.django.test.Client` now supports automatic JSON
  178. serialization of list and tuple ``data`` when
  179. ``content_type='application/json'``.
  180. * The new :setting:`ORACLE_MANAGED_FILES <TEST_ORACLE_MANAGED_FILES>` test
  181. database setting allows using Oracle Managed Files (OMF) tablespaces.
  182. * Deferrable database constraints are now checked at the end of each
  183. :class:`~django.test.TestCase` test on SQLite 3.20+, just like on other
  184. backends that support deferrable constraints. These checks aren't implemented
  185. for older versions of SQLite because they would require expensive table
  186. introspection there.
  187. URLs
  188. ~~~~
  189. * The new :attr:`.ResolverMatch.route` attribute stores the route of the
  190. matching URL pattern.
  191. Validators
  192. ~~~~~~~~~~
  193. * :class:`.MaxValueValidator`, :class:`.MinValueValidator`,
  194. :class:`.MinLengthValidator`, and :class:`.MaxLengthValidator` now accept
  195. a callable ``limit_value``.
  196. .. _backwards-incompatible-2.2:
  197. Backwards incompatible changes in 2.2
  198. =====================================
  199. Database backend API
  200. --------------------
  201. This section describes changes that may be needed in third-party database
  202. backends.
  203. * Third-party database backends must implement support for table check
  204. constraints or set ``DatabaseFeatures.supports_table_check_constraints`` to
  205. ``False``.
  206. * Third party database backends must implement support for ignoring
  207. constraints or uniqueness errors while inserting or set
  208. ``DatabaseFeatures.supports_ignore_conflicts`` to ``False``.
  209. * Third party database backends must implement introspection for
  210. ``DurationField`` or set ``DatabaseFeatures.can_introspect_duration_field``
  211. to ``False``.
  212. * ``DatabaseFeatures.uses_savepoints`` now defaults to ``True``.
  213. * Third party database backends must implement support for partial indexes or
  214. set ``DatabaseFeatures.supports_partial_indexes`` to ``False``.
  215. * Several ``SchemaEditor`` attributes are changed:
  216. * ``sql_create_check`` is replaced with ``sql_create_constraint``.
  217. * ``sql_delete_check`` is replaced with ``sql_delete_constraint``.
  218. * ``sql_create_fk`` is replaced with ``sql_foreign_key_constraint``,
  219. ``sql_constraint``, and ``sql_create_constraint``.
  220. * ``DatabaseIntrospection.table_name_converter()`` and
  221. ``column_name_converter()`` are removed. Third party database backends may
  222. need to instead implement ``DatabaseIntrospection.identifier_converter()``.
  223. In that case, the constraint names that
  224. ``DatabaseIntrospection.get_constraints()`` returns must be normalized by
  225. ``identifier_converter()``.
  226. Admin actions are no longer collected from base ``ModelAdmin`` classes
  227. ----------------------------------------------------------------------
  228. For example, in older versions of Django::
  229. from django.contrib import admin
  230. class BaseAdmin(admin.ModelAdmin):
  231. actions = ['a']
  232. class SubAdmin(BaseAdmin):
  233. actions = ['b']
  234. ``SubAdmin`` will have actions ``'a'`` and ``'b'``.
  235. Now ``actions`` follows standard Python inheritance. To get the same result as
  236. before::
  237. class SubAdmin(BaseAdmin):
  238. actions = BaseAdmin.actions + ['b']
  239. :mod:`django.contrib.gis`
  240. -------------------------
  241. * Support for GDAL 1.9 and 1.10 is dropped.
  242. ``TransactionTestCase`` serialized data loading
  243. -----------------------------------------------
  244. Initial data migrations are now loaded in
  245. :class:`~django.test.TransactionTestCase` at the end of the test, after the
  246. database flush. In older versions, this data was loaded at the beginning of the
  247. test, but this prevents the :option:`test --keepdb` option from working
  248. properly (the database was empty at the end of the whole test suite). This
  249. change shouldn't have an impact on your tests unless you've customized
  250. :class:`~django.test.TransactionTestCase`'s internals.
  251. ``sqlparse`` is required dependency
  252. -----------------------------------
  253. To simplify a few parts of Django's database handling, `sqlparse
  254. <https://pypi.org/project/sqlparse/>`_ is now a required dependency. It's
  255. automatically installed along with Django.
  256. ``cached_property`` aliases
  257. ---------------------------
  258. In usage like::
  259. from django.utils.functional import cached_property
  260. class A:
  261. @cached_property
  262. def base(self):
  263. return ...
  264. alias = base
  265. ``alias`` is not cached. Such usage now raises ``TypeError: Cannot assign the
  266. same cached_property to two different names ('base' and 'alias').`` on Python
  267. 3.6 and later.
  268. Use this instead::
  269. import operator
  270. class A:
  271. ...
  272. alias = property(operator.attrgetter('base'))
  273. Miscellaneous
  274. -------------
  275. * To improve readability, the ``UUIDField`` form field now displays values with
  276. dashes, e.g. ``550e8400-e29b-41d4-a716-446655440000`` instead of
  277. ``550e8400e29b41d4a716446655440000``.
  278. * On SQLite, ``PositiveIntegerField`` and ``PositiveSmallIntegerField`` now
  279. include a check constraint to prevent negative values in the database. If you
  280. have existing invalid data and run a migration that recreates a table, you'll
  281. see ``CHECK constraint failed``.
  282. * For consistency with WSGI servers, the test client now sets the
  283. ``Content-Length`` header to a string rather than an integer.
  284. * The return value of :func:`django.utils.text.slugify` is no longer marked as
  285. HTML safe.
  286. * The default truncation character used by the :tfilter:`urlizetrunc`,
  287. :tfilter:`truncatechars`, :tfilter:`truncatechars_html`,
  288. :tfilter:`truncatewords`, and :tfilter:`truncatewords_html` template filters
  289. is now the real ellipsis character (``…``) instead of 3 dots. You may have to
  290. adapt some test output comparisons.
  291. * Support for bytestring paths in the template filesystem loader is removed.
  292. * :func:`django.utils.http.urlsafe_base64_encode` now returns a string instead
  293. of a bytestring, and :func:`django.utils.http.urlsafe_base64_decode` may no
  294. longer be passed a bytestring.
  295. * Support for ``cx_Oracle`` < 6.0 is removed.
  296. * The minimum supported version of ``mysqlclient`` is increased from 1.3.7 to
  297. 1.3.13.
  298. * The minimum supported version of SQLite is increased from 3.7.15 to 3.8.3.
  299. * In an attempt to provide more semantic query data, ``NullBooleanSelect`` now
  300. renders ``<option>`` values of ``unknown``, ``true``, and ``false`` instead
  301. of ``1``, ``2``, and ``3``. For backwards compatibility, the old values are
  302. still accepted as data.
  303. * :attr:`Group.name <django.contrib.auth.models.Group.name>` ``max_length``
  304. is increased from 80 to 150 characters.
  305. * Tests that violate deferrable database constraints now error when run on
  306. SQLite 3.20+, just like on other backends that support such constraints.
  307. .. _deprecated-features-2.2:
  308. Features deprecated in 2.2
  309. ==========================
  310. Model ``Meta.ordering`` will no longer affect ``GROUP BY`` queries
  311. ------------------------------------------------------------------
  312. A model's ``Meta.ordering`` affecting ``GROUP BY`` queries (such as
  313. ``.annotate().values()``) is a common source of confusion. Such queries now
  314. issue a deprecation warning with the advice to add an ``order_by()`` to retain
  315. the current query. ``Meta.ordering`` will be ignored in such queries starting
  316. in Django 3.1.
  317. Miscellaneous
  318. -------------
  319. * ``django.utils.timezone.FixedOffset`` is deprecated in favor of
  320. :class:`datetime.timezone`.
  321. * The undocumented ``QuerySetPaginator`` alias of
  322. ``django.core.paginator.Paginator`` is deprecated.
  323. * The ``FloatRangeField`` model and form fields in ``django.contrib.postgres``
  324. are deprecated in favor of a new name, ``DecimalRangeField``, to match the
  325. underlying ``numrange`` data type used in the database.
  326. * The ``FILE_CHARSET`` setting is deprecated. Starting with Django 3.1, files
  327. read from disk must be UTF-8 encoded.
  328. * ``django.contrib.staticfiles.storage.CachedStaticFilesStorage`` is
  329. deprecated due to the intractable problems that is has. Use
  330. :class:`.ManifestStaticFilesStorage` or a third-party cloud storage instead.