2.2.txt 13 KB

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