2.1.txt 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. ========================
  2. Django 2.1 release notes
  3. ========================
  4. *August 1, 2018*
  5. Welcome to Django 2.1!
  6. These release notes cover the :ref:`new features <whats-new-2.1>`, as well as
  7. some :ref:`backwards incompatible changes <backwards-incompatible-2.1>` you'll
  8. want to be aware of when upgrading from Django 2.0 or earlier. We've
  9. :ref:`dropped some features<removed-features-2.1>` that have reached the end of
  10. their deprecation cycle, and we've :ref:`begun the deprecation process for some
  11. features <deprecated-features-2.1>`.
  12. See the :doc:`/howto/upgrade-version` guide if you're updating an existing
  13. project.
  14. Python compatibility
  15. ====================
  16. Django 2.1 supports Python 3.5, 3.6, and 3.7. Django 2.0 is the last version to
  17. support Python 3.4. We **highly recommend** and only officially support the
  18. latest release of each series.
  19. .. _whats-new-2.1:
  20. What's new in Django 2.1
  21. ========================
  22. Model "view" permission
  23. -----------------------
  24. A "view" permission is added to the model :attr:`Meta.default_permissions
  25. <django.db.models.Options.default_permissions>`. The new permissions will be
  26. created automatically when running :djadmin:`migrate`.
  27. This allows giving users read-only access to models in the admin.
  28. :meth:`.ModelAdmin.has_view_permission` is new. The implementation is backwards
  29. compatible in that there isn't a need to assign the "view" permission to allow
  30. users who have the "change" permission to edit objects.
  31. There are a couple of :ref:`backwards incompatible considerations
  32. <view_permission_backwards_incompatible>`.
  33. Minor features
  34. --------------
  35. :mod:`django.contrib.admin`
  36. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  37. * :attr:`.ModelAdmin.search_fields` now accepts any lookup such as
  38. ``field__exact``.
  39. * jQuery is upgraded from version 2.2.3 to 3.3.1.
  40. * The new :meth:`.ModelAdmin.delete_queryset` method allows customizing the
  41. deletion process of the "delete selected objects" action.
  42. * You can now :ref:`override the default admin site
  43. <overriding-default-admin-site>`.
  44. * The new :attr:`.ModelAdmin.sortable_by` attribute and
  45. :meth:`.ModelAdmin.get_sortable_by` method allow limiting the columns that
  46. can be sorted in the change list page.
  47. * The ``admin_order_field`` attribute for elements in
  48. :attr:`.ModelAdmin.list_display` may now be a query expression.
  49. * The new :meth:`.ModelAdmin.get_deleted_objects()` method allows customizing
  50. the deletion process of the delete view and the "delete selected" action.
  51. * The ``actions.html``, ``change_list_results.html``, ``date_hierarchy.html``,
  52. ``pagination.html``, ``prepopulated_fields_js.html``, ``search_form.html``,
  53. and ``submit_line.html`` templates can now be :ref:`overridden per app or
  54. per model <admin-templates-overridden-per-app-or-model>` (besides overridden
  55. globally).
  56. * The admin change list and change form object tools can now be :ref:`overridden
  57. per app, per model, or globally <admin-templates-overridden-per-app-or-model>`
  58. with ``change_list_object_tools.html`` and
  59. ``change_form_object_tools.html`` templates.
  60. * :meth:`.InlineModelAdmin.has_add_permission` is now passed the parent object
  61. as the second positional argument, ``obj``.
  62. * Admin actions may now :ref:`specify permissions <admin-action-permissions>`
  63. to limit their availability to certain users.
  64. :mod:`django.contrib.auth`
  65. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  66. * :djadmin:`createsuperuser` now gives a prompt to allow bypassing the
  67. :setting:`AUTH_PASSWORD_VALIDATORS` checks.
  68. :mod:`django.contrib.gis`
  69. ~~~~~~~~~~~~~~~~~~~~~~~~~
  70. * The new :meth:`.GEOSGeometry.buffer_with_style` method is a version of
  71. :meth:`~.GEOSGeometry.buffer` that allows customizing the style of the
  72. buffer.
  73. * :class:`~django.contrib.gis.forms.widgets.OpenLayersWidget` is now based on
  74. OpenLayers 4.6.5 (previously 3.20.1).
  75. :mod:`django.contrib.sessions`
  76. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  77. * Added the :setting:`SESSION_COOKIE_SAMESITE` setting to set the ``SameSite``
  78. cookie flag on session cookies.
  79. Cache
  80. ~~~~~
  81. * The :ref:`local-memory cache backend <local-memory-caching>` now uses a
  82. least-recently-used (LRU) culling strategy rather than a pseudo-random one.
  83. * The new :meth:`~django.core.caches.cache.touch` method of the :ref:`low-level
  84. cache API <low-level-cache-api>` updates the timeout of cache keys.
  85. CSRF
  86. ~~~~
  87. * Added the :setting:`CSRF_COOKIE_SAMESITE` setting to set the ``SameSite``
  88. cookie flag on CSRF cookies.
  89. Forms
  90. ~~~~~
  91. * The widget for ``ImageField`` now renders with the HTML attribute
  92. ``accept="image/*"``.
  93. Internationalization
  94. ~~~~~~~~~~~~~~~~~~~~
  95. * Added the :meth:`~django.utils.translation.get_supported_language_variant`
  96. function.
  97. * Untranslated strings for territorial language variants now use the
  98. translations of the generic language. For example, untranslated ``pt_BR``
  99. strings use ``pt`` translations.
  100. Management Commands
  101. ~~~~~~~~~~~~~~~~~~~
  102. * The new :option:`inspectdb --include-views` option allows creating models
  103. for database views.
  104. * The :class:`~django.core.management.BaseCommand` class now uses a custom help
  105. formatter so that the standard options like ``--verbosity`` or ``--settings``
  106. appear last in the help output, giving a more prominent position to subclassed
  107. command's options.
  108. Migrations
  109. ~~~~~~~~~~
  110. * Added support for serialization of ``functools.partialmethod`` objects.
  111. * To support frozen environments, migrations may be loaded from ``.pyc`` files.
  112. Models
  113. ~~~~~~
  114. * Models can now use ``__init_subclass__()`` from :pep:`487`.
  115. * A ``BinaryField`` may now be set to ``editable=True`` if you wish to include
  116. it in model forms.
  117. * A number of new text database functions are added:
  118. :class:`~django.db.models.functions.Chr`,
  119. :class:`~django.db.models.functions.Left`,
  120. :class:`~django.db.models.functions.LPad`,
  121. :class:`~django.db.models.functions.LTrim`,
  122. :class:`~django.db.models.functions.Ord`,
  123. :class:`~django.db.models.functions.Repeat`,
  124. :class:`~django.db.models.functions.Replace`,
  125. :class:`~django.db.models.functions.Right`,
  126. :class:`~django.db.models.functions.RPad`,
  127. :class:`~django.db.models.functions.RTrim`, and
  128. :class:`~django.db.models.functions.Trim`.
  129. * The new :class:`~django.db.models.functions.TruncWeek` function truncates
  130. :class:`~django.db.models.DateField` and
  131. :class:`~django.db.models.DateTimeField` to the Monday of a week.
  132. * Query expressions can now be negated using a minus sign.
  133. * :meth:`.QuerySet.order_by` and :meth:`distinct(*fields) <.QuerySet.distinct>`
  134. now support using field transforms.
  135. * :class:`~django.db.models.BooleanField` can now be ``null=True``. This is
  136. encouraged instead of ``NullBooleanField``, which will likely be deprecated
  137. in the future.
  138. * The new :meth:`.QuerySet.explain` method displays the database's execution
  139. plan of a queryset's query.
  140. * :meth:`.QuerySet.raw` now supports :meth:`~.QuerySet.prefetch_related`.
  141. Requests and Responses
  142. ~~~~~~~~~~~~~~~~~~~~~~
  143. * Added :meth:`.HttpRequest.get_full_path_info`.
  144. * Added the ``samesite`` argument to :meth:`.HttpResponse.set_cookie` to allow
  145. setting the ``SameSite`` cookie flag.
  146. * The new ``as_attachment`` argument for :class:`~django.http.FileResponse`
  147. sets the ``Content-Disposition`` header to make the browser ask if the user
  148. wants to download the file. ``FileResponse`` also tries to set the
  149. ``Content-Type`` and ``Content-Length`` headers where appropriate.
  150. Templates
  151. ~~~~~~~~~
  152. * The new :tfilter:`json_script` filter safely outputs a Python object as JSON,
  153. wrapped in a ``<script>`` tag, ready for use with JavaScript.
  154. Tests
  155. ~~~~~
  156. * Added test :class:`~django.test.Client` support for 307 and 308 redirects.
  157. * The test :class:`~django.test.Client` now serializes a request data
  158. dictionary as JSON if ``content_type='application/json'``. You can customize
  159. the JSON encoder with test client's ``json_encoder`` parameter.
  160. * The new :meth:`.SimpleTestCase.assertWarnsMessage` method is a simpler
  161. version of :meth:`~unittest.TestCase.assertWarnsRegex`.
  162. .. _backwards-incompatible-2.1:
  163. Backwards incompatible changes in 2.1
  164. =====================================
  165. Database backend API
  166. --------------------
  167. This section describes changes that may be needed in third-party database
  168. backends.
  169. * To adhere to :pep:`249`, exceptions where a database doesn't support a
  170. feature are changed from :exc:`NotImplementedError` to
  171. :exc:`django.db.NotSupportedError`.
  172. * Renamed the ``allow_sliced_subqueries`` database feature flag to
  173. ``allow_sliced_subqueries_with_in``.
  174. * ``DatabaseOperations.distinct_sql()`` now requires an additional ``params``
  175. argument and returns a tuple of SQL and parameters instead of an SQL string.
  176. * ``DatabaseFeatures.introspected_boolean_field_type`` is changed from a method
  177. to a property.
  178. :mod:`django.contrib.gis`
  179. -------------------------
  180. * Support for SpatiaLite 4.0 is removed.
  181. Dropped support for MySQL 5.5
  182. -----------------------------
  183. The end of upstream support for MySQL 5.5 is December 2018. Django 2.1 supports
  184. MySQL 5.6 and higher.
  185. Dropped support for PostgreSQL 9.3
  186. ----------------------------------
  187. The end of upstream support for PostgreSQL 9.3 is September 2018. Django 2.1
  188. supports PostgreSQL 9.4 and higher.
  189. Removed ``BCryptPasswordHasher`` from the default ``PASSWORD_HASHERS`` setting
  190. ------------------------------------------------------------------------------
  191. If you used bcrypt with Django 1.4 or 1.5 (before ``BCryptSHA256PasswordHasher``
  192. was added in Django 1.6), you might have some passwords that use the
  193. ``BCryptPasswordHasher`` hasher.
  194. You can check if that's the case like this::
  195. from django.contrib.auth import get_user_model
  196. User = get_user_model()
  197. User.objects.filter(password__startswith='bcrypt$$')
  198. If you want to continue to allow those passwords to be used, you'll
  199. have to define the :setting:`PASSWORD_HASHERS` setting (if you don't already)
  200. and include ``'django.contrib.auth.hashers.BCryptPasswordHasher'``.
  201. Moved ``wrap_label`` widget template context variable
  202. -----------------------------------------------------
  203. To fix the lack of ``<label>`` when using ``RadioSelect`` and
  204. ``CheckboxSelectMultiple`` with ``MultiWidget``, the ``wrap_label`` context
  205. variable now appears as an attribute of each option. For example, in a custom
  206. ``input_option.html`` template, change ``{% if wrap_label %}`` to
  207. ``{% if widget.wrap_label %}``.
  208. ``SameSite`` cookies
  209. --------------------
  210. The cookies used for ``django.contrib.sessions``, ``django.contrib.messages``,
  211. and Django's CSRF protection now set the ``SameSite`` flag to ``Lax`` by
  212. default. Browsers that respect this flag won't send these cookies on
  213. cross-origin requests. If you rely on the old behavior, set the
  214. :setting:`SESSION_COOKIE_SAMESITE` and/or :setting:`CSRF_COOKIE_SAMESITE`
  215. setting to ``None``.
  216. .. _view_permission_backwards_incompatible:
  217. Considerations for the new model "view" permission
  218. --------------------------------------------------
  219. Custom admin forms need to take the view-only case into account
  220. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  221. With the new "view" permission, existing custom admin forms may raise errors
  222. when a user doesn't have the change permission because the form might access
  223. nonexistent fields. Fix this by overriding :meth:`.ModelAdmin.get_form` and
  224. checking if the user has the "change" permissions and returning the default
  225. form if not::
  226. class MyAdmin(admin.ModelAdmin):
  227. def get_form(self, request, obj=None, **kwargs):
  228. if not self.has_change_permission(request, obj):
  229. return super().get_form(request, obj, **kwargs)
  230. return CustomForm
  231. New default view permission could allow unwanted access to admin views
  232. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  233. If you have a custom permission with a codename of the form
  234. ``view_<modelname>``, the new view permission handling in the admin will allow
  235. view access to the changelist and detail pages for those models. If this is
  236. unwanted, you must change your custom permission codename.
  237. Miscellaneous
  238. -------------
  239. * The minimum supported version of ``mysqlclient`` is increased from 1.3.3 to
  240. 1.3.7.
  241. * Support for SQLite < 3.7.15 is removed.
  242. * The date format of ``Set-Cookie``'s ``Expires`` directive is changed to
  243. follow :rfc:`7231#section-7.1.1.1` instead of Netscape's cookie standard.
  244. Hyphens present in dates like ``Tue, 25-Dec-2018 22:26:13 GMT`` are removed.
  245. This change should be merely cosmetic except perhaps for antiquated browsers
  246. that don't parse the new format.
  247. * ``allowed_hosts`` is now a required argument of private API
  248. ``django.utils.http.is_safe_url()``.
  249. * The ``multiple`` attribute rendered by the
  250. :class:`~django.forms.SelectMultiple` widget now uses HTML5 boolean syntax
  251. rather than XHTML's ``multiple="multiple"``.
  252. * HTML rendered by form widgets no longer includes a closing slash on void
  253. elements, e.g. ``<br>``. This is incompatible within XHTML, although some
  254. widgets already used aspects of HTML5 such as boolean attributes.
  255. * The value of :class:`~django.forms.SelectDateWidget`'s empty options is
  256. changed from 0 to an empty string, which mainly may require some adjustments
  257. in tests that compare HTML.
  258. * :meth:`.User.has_usable_password` and the
  259. :func:`~django.contrib.auth.hashers.is_password_usable` function no longer
  260. return ``False`` if the password is ``None`` or an empty string, or if the
  261. password uses a hasher that's not in the :setting:`PASSWORD_HASHERS` setting.
  262. This undocumented behavior was a regression in Django 1.6 and prevented users
  263. with such passwords from requesting a password reset. Audit your code to
  264. confirm that your usage of these APIs don't rely on the old behavior.
  265. * Since migrations are now loaded from ``.pyc`` files, you might need to delete
  266. them if you're working in a mixed Python 2 and Python 3 environment.
  267. * Using ``None`` as a ``django.contrib.postgres.fields.JSONField`` lookup
  268. value now matches objects that have the specified key and a null value rather
  269. than objects that don't have the key.
  270. * The admin CSS class ``field-box`` is renamed to ``fieldBox`` to prevent
  271. conflicts with the class given to model fields named "box".
  272. * Since the admin's ``actions.html``, ``change_list_results.html``,
  273. ``date_hierarchy.html``, ``pagination.html``, ``prepopulated_fields_js.html``,
  274. ``search_form.html``, and ``submit_line.html`` templates can now be
  275. overridden per app or per model, you may need to rename existing templates
  276. with those names that were written for a different purpose.
  277. * ``QuerySet.raw()`` now caches its results like regular querysets. Use
  278. ``iterator()`` if you don't want caching.
  279. * The database router :meth:`allow_relation` method is called in more cases.
  280. Improperly written routers may need to be updated accordingly.
  281. * Translations are no longer deactivated before running management commands.
  282. If your custom command requires translations to be deactivated (for example,
  283. to insert untranslated content into the database), use the new
  284. :ref:`@no_translations decorator <management-commands-and-locales>`.
  285. * Management commands no longer allow the abbreviated forms of the
  286. ``--settings`` and ``--pythonpath`` arguments.
  287. * The private ``django.db.models.sql.constants.QUERY_TERMS`` constant is
  288. removed. The :meth:`~.RegisterLookupMixin.get_lookup`
  289. and :meth:`~.RegisterLookupMixin.get_lookups` methods
  290. of the :ref:`Lookup Registration API <lookup-registration-api>` may be
  291. suitable alternatives. Compared to the ``QUERY_TERMS`` constant, they allow
  292. your code to also account for any custom lookups that have been registered.
  293. * Compatibility with ``py-bcrypt`` is removed as it's unmaintained. Use `bcrypt
  294. <https://pypi.org/project/bcrypt/>`_ instead.
  295. .. _deprecated-features-2.1:
  296. Features deprecated in 2.1
  297. ==========================
  298. Miscellaneous
  299. -------------
  300. * The ``ForceRHR`` GIS function is deprecated in favor of the new
  301. :class:`~django.contrib.gis.db.models.functions.ForcePolygonCW` function.
  302. * ``django.utils.http.cookie_date()`` is deprecated in favor of
  303. :func:`~django.utils.http.http_date`, which follows the format of the latest
  304. RFC.
  305. * ``{% load staticfiles %}`` and ``{% load admin_static %}`` are deprecated
  306. in favor of ``{% load static %}``, which works the same.
  307. * ``django.contrib.staticfiles.templatetags.static()`` is deprecated in favor
  308. of ``django.templatetags.static.static()``.
  309. * Support for :meth:`.InlineModelAdmin.has_add_permission` methods that don't
  310. accept ``obj`` as the second positional argument will be removed in Django
  311. 3.0.
  312. .. _removed-features-2.1:
  313. Features removed in 2.1
  314. =======================
  315. These features have reached the end of their deprecation cycle and are removed
  316. in Django 2.1. See :ref:`deprecated-features-1.11` for details, including how
  317. to remove usage of these features.
  318. * ``contrib.auth.views.login()``, ``logout()``, ``password_change()``,
  319. ``password_change_done()``, ``password_reset()``, ``password_reset_done()``,
  320. ``password_reset_confirm()``, and ``password_reset_complete()`` are removed.
  321. * The ``extra_context`` parameter of ``contrib.auth.views.logout_then_login()``
  322. is removed.
  323. * ``django.test.runner.setup_databases()`` is removed.
  324. * ``django.utils.translation.string_concat()`` is removed.
  325. * ``django.core.cache.backends.memcached.PyLibMCCache`` no longer supports
  326. passing ``pylibmc`` behavior settings as top-level attributes of ``OPTIONS``.
  327. * The ``host`` parameter of ``django.utils.http.is_safe_url()`` is removed.
  328. * Silencing of exceptions raised while rendering the ``{% include %}`` template
  329. tag is removed.
  330. * ``DatabaseIntrospection.get_indexes()`` is removed.
  331. * The ``authenticate()`` method of authentication backends requires ``request``
  332. as the first positional argument.
  333. * The ``django.db.models.permalink()`` decorator is removed.
  334. * The ``USE_ETAGS`` setting is removed. ``CommonMiddleware`` and
  335. ``django.utils.cache.patch_response_headers()`` no longer set ETags.
  336. * The ``Model._meta.has_auto_field`` attribute is removed.
  337. * ``url()``'s support for inline flags in regular expression groups (``(?i)``,
  338. ``(?L)``, ``(?m)``, ``(?s)``, and ``(?u)``) is removed.
  339. * Support for ``Widget.render()`` methods without the ``renderer`` argument
  340. is removed.