2.0.txt 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855
  1. ========================
  2. Django 2.0 release notes
  3. ========================
  4. *December 2, 2017*
  5. Welcome to Django 2.0!
  6. These release notes cover the :ref:`new features <whats-new-2.0>`, as well as
  7. some :ref:`backwards incompatible changes <backwards-incompatible-2.0>` you'll
  8. want to be aware of when upgrading from Django 1.11 or earlier. We've
  9. :ref:`dropped some features<removed-features-2.0>` 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.0>`.
  12. This release starts Django's use of a :ref:`loose form of semantic versioning
  13. <internal-release-cadence>`, but there aren't any major backwards incompatible
  14. changes that might be expected of a 2.0 release. Upgrading should be a similar
  15. amount of effort as past feature releases.
  16. See the :doc:`/howto/upgrade-version` guide if you're updating an existing
  17. project.
  18. Python compatibility
  19. ====================
  20. Django 2.0 supports Python 3.4, 3.5, 3.6, and 3.7. We **highly recommend** and
  21. only officially support the latest release of each series.
  22. The Django 1.11.x series is the last to support Python 2.7.
  23. Django 2.0 will be the last release series to support Python 3.4. If you plan
  24. a deployment of Python 3.4 beyond the end-of-life for Django 2.0 (April 2019),
  25. stick with Django 1.11 LTS (supported until April 2020) instead. Note, however,
  26. that the end-of-life for Python 3.4 is March 2019.
  27. Third-party library support for older version of Django
  28. =======================================================
  29. Following the release of Django 2.0, we suggest that third-party app authors
  30. drop support for all versions of Django prior to 1.11. At that time, you should
  31. be able to run your package's tests using ``python -Wd`` so that deprecation
  32. warnings do appear. After making the deprecation warning fixes, your app should
  33. be compatible with Django 2.0.
  34. .. _whats-new-2.0:
  35. What's new in Django 2.0
  36. ========================
  37. Simplified URL routing syntax
  38. -----------------------------
  39. The new :func:`django.urls.path()` function allows a simpler, more readable URL
  40. routing syntax. For example, this example from previous Django releases::
  41. url(r'^articles/(?P<year>[0-9]{4})/$', views.year_archive),
  42. could be written as::
  43. path('articles/<int:year>/', views.year_archive),
  44. The new syntax supports type coercion of URL parameters. In the example, the
  45. view will receive the ``year`` keyword argument as an integer rather than as
  46. a string. Also, the URLs that will match are slightly less constrained in the
  47. rewritten example. For example, the year 10000 will now match since the year
  48. integers aren't constrained to be exactly four digits long as they are in the
  49. regular expression.
  50. The ``django.conf.urls.url()`` function from previous versions is now available
  51. as :func:`django.urls.re_path`. The old location remains for backwards
  52. compatibility, without an imminent deprecation. The old
  53. ``django.conf.urls.include()`` function is now importable from ``django.urls``
  54. so you can use ``from django.urls import include, path, re_path`` in your
  55. URLconfs.
  56. The :doc:`/topics/http/urls` document is rewritten to feature the new syntax
  57. and provide more details.
  58. Mobile-friendly ``contrib.admin``
  59. ---------------------------------
  60. The admin is now responsive and supports all major mobile devices. Older
  61. browsers may experience varying levels of graceful degradation.
  62. Window expressions
  63. ------------------
  64. The new :class:`~django.db.models.expressions.Window` expression allows
  65. adding an ``OVER`` clause to querysets. You can use :ref:`window functions
  66. <window-functions>` and :ref:`aggregate functions <aggregation-functions>` in
  67. the expression.
  68. Minor features
  69. --------------
  70. :mod:`django.contrib.admin`
  71. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  72. * The new :attr:`.ModelAdmin.autocomplete_fields` attribute and
  73. :meth:`.ModelAdmin.get_autocomplete_fields` method allow using a
  74. `Select2 <https://select2.org>`_ search widget for ``ForeignKey`` and
  75. ``ManyToManyField``.
  76. :mod:`django.contrib.auth`
  77. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  78. * The default iteration count for the PBKDF2 password hasher is increased from
  79. 36,000 to 100,000.
  80. :mod:`django.contrib.gis`
  81. ~~~~~~~~~~~~~~~~~~~~~~~~~
  82. * Added MySQL support for the
  83. :class:`~django.contrib.gis.db.models.functions.AsGeoJSON` function,
  84. :class:`~django.contrib.gis.db.models.functions.GeoHash` function,
  85. :class:`~django.contrib.gis.db.models.functions.IsValid` function,
  86. :lookup:`isvalid` lookup, and :ref:`distance lookups <distance-lookups>`.
  87. * Added the :class:`~django.contrib.gis.db.models.functions.Azimuth` and
  88. :class:`~django.contrib.gis.db.models.functions.LineLocatePoint` functions,
  89. supported on PostGIS and SpatiaLite.
  90. * Any :class:`~django.contrib.gis.geos.GEOSGeometry` imported from GeoJSON now
  91. has its SRID set.
  92. * Added the :attr:`.OSMWidget.default_zoom` attribute to customize the map's
  93. default zoom level.
  94. * Made metadata readable and editable on rasters through the
  95. :attr:`~django.contrib.gis.gdal.GDALRaster.metadata`,
  96. :attr:`~django.contrib.gis.gdal.GDALRaster.info`, and
  97. :attr:`~django.contrib.gis.gdal.GDALBand.metadata` attributes.
  98. * Allowed passing driver-specific creation options to
  99. :class:`~django.contrib.gis.gdal.GDALRaster` objects using ``papsz_options``.
  100. * Allowed creating :class:`~django.contrib.gis.gdal.GDALRaster` objects in
  101. GDAL's internal virtual filesystem. Rasters can now be :ref:`created from and
  102. converted to binary data <gdal-raster-vsimem>` in-memory.
  103. * The new :meth:`GDALBand.color_interp()
  104. <django.contrib.gis.gdal.GDALBand.color_interp>` method returns the color
  105. interpretation for the band.
  106. :mod:`django.contrib.postgres`
  107. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  108. * The new ``distinct`` argument for
  109. :class:`~django.contrib.postgres.aggregates.ArrayAgg` determines if
  110. concatenated values will be distinct.
  111. * The new :class:`~django.contrib.postgres.functions.RandomUUID` database
  112. function returns a version 4 UUID. It requires use of PostgreSQL's
  113. ``pgcrypto`` extension which can be activated using the new
  114. :class:`~django.contrib.postgres.operations.CryptoExtension` migration
  115. operation.
  116. * :class:`django.contrib.postgres.indexes.GinIndex` now supports the
  117. ``fastupdate`` and ``gin_pending_list_limit`` parameters.
  118. * The new :class:`~django.contrib.postgres.indexes.GistIndex` class allows
  119. creating ``GiST`` indexes in the database. The new
  120. :class:`~django.contrib.postgres.operations.BtreeGistExtension` migration
  121. operation installs the ``btree_gist`` extension to add support for operator
  122. classes that aren't built-in.
  123. * :djadmin:`inspectdb` can now introspect ``JSONField`` and various
  124. ``RangeField``\s (``django.contrib.postgres`` must be in ``INSTALLED_APPS``).
  125. :mod:`django.contrib.sitemaps`
  126. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  127. * Added the ``protocol`` keyword argument to the
  128. :class:`~django.contrib.sitemaps.GenericSitemap` constructor.
  129. Cache
  130. ~~~~~
  131. * ``cache.set_many()`` now returns a list of keys that failed to be inserted.
  132. For the built-in backends, failed inserts can only happen on memcached.
  133. File Storage
  134. ~~~~~~~~~~~~
  135. * :meth:`File.open() <django.core.files.File.open>` can be used as a context
  136. manager, e.g. ``with file.open() as f:``.
  137. Forms
  138. ~~~~~
  139. * The new ``date_attrs`` and ``time_attrs`` arguments for
  140. :class:`~django.forms.SplitDateTimeWidget` and
  141. :class:`~django.forms.SplitHiddenDateTimeWidget` allow specifying different
  142. HTML attributes for the ``DateInput`` and ``TimeInput`` (or hidden)
  143. subwidgets.
  144. * The new :meth:`Form.errors.get_json_data()
  145. <django.forms.Form.errors.get_json_data>` method returns form errors as
  146. a dictionary suitable for including in a JSON response.
  147. Generic Views
  148. ~~~~~~~~~~~~~
  149. * The new :attr:`.ContextMixin.extra_context` attribute allows adding context
  150. in ``View.as_view()``.
  151. Management Commands
  152. ~~~~~~~~~~~~~~~~~~~
  153. * :djadmin:`inspectdb` now translates MySQL's unsigned integer columns to
  154. ``PositiveIntegerField`` or ``PositiveSmallIntegerField``.
  155. * The new :option:`makemessages --add-location` option controls the comment
  156. format in PO files.
  157. * :djadmin:`loaddata` can now :ref:`read from stdin <loading-fixtures-stdin>`.
  158. * The new :option:`diffsettings --output` option allows formatting the output
  159. in a unified diff format.
  160. * On Oracle, :djadmin:`inspectdb` can now introspect ``AutoField`` if the
  161. column is created as an identity column.
  162. * On MySQL, :djadmin:`dbshell` now supports client-side TLS certificates.
  163. Migrations
  164. ~~~~~~~~~~
  165. * The new :option:`squashmigrations --squashed-name` option allows naming the
  166. squashed migration.
  167. Models
  168. ~~~~~~
  169. * The new :class:`~django.db.models.functions.StrIndex` database function
  170. finds the starting index of a string inside another string.
  171. * On Oracle, ``AutoField`` and ``BigAutoField`` are now created as `identity
  172. columns`_.
  173. .. _`identity columns`: https://docs.oracle.com/database/121/DRDAA/migr_tools_feat.htm#DRDAA109
  174. * The new ``chunk_size`` parameter of :meth:`.QuerySet.iterator` controls the
  175. number of rows fetched by the Python database client when streaming results
  176. from the database. For databases that don't support server-side cursors, it
  177. controls the number of results Django fetches from the database adapter.
  178. * :meth:`.QuerySet.earliest`, :meth:`.QuerySet.latest`, and
  179. :attr:`Meta.get_latest_by <django.db.models.Options.get_latest_by>` now
  180. allow ordering by several fields.
  181. * Added the :class:`~django.db.models.functions.ExtractQuarter` function to
  182. extract the quarter from :class:`~django.db.models.DateField` and
  183. :class:`~django.db.models.DateTimeField`, and exposed it through the
  184. :lookup:`quarter` lookup.
  185. * Added the :class:`~django.db.models.functions.TruncQuarter` function to
  186. truncate :class:`~django.db.models.DateField` and
  187. :class:`~django.db.models.DateTimeField` to the first day of a quarter.
  188. * Added the :attr:`~django.db.models.Index.db_tablespace` parameter to
  189. class-based indexes.
  190. * If the database supports a native duration field (Oracle and PostgreSQL),
  191. :class:`~django.db.models.functions.Extract` now works with
  192. :class:`~django.db.models.DurationField`.
  193. * Added the ``of`` argument to :meth:`.QuerySet.select_for_update()`, supported
  194. on PostgreSQL and Oracle, to lock only rows from specific tables rather than
  195. all selected tables. It may be helpful particularly when
  196. :meth:`~.QuerySet.select_for_update()` is used in conjunction with
  197. :meth:`~.QuerySet.select_related()`.
  198. * The new ``field_name`` parameter of :meth:`.QuerySet.in_bulk` allows fetching
  199. results based on any unique model field.
  200. * :meth:`.CursorWrapper.callproc()` now takes an optional dictionary of keyword
  201. parameters, if the backend supports this feature. Of Django's built-in
  202. backends, only Oracle supports it.
  203. * The new :meth:`connection.execute_wrapper()
  204. <django.db.backends.base.DatabaseWrapper.execute_wrapper>` method allows
  205. :doc:`installing wrappers around execution of database queries
  206. </topics/db/instrumentation>`.
  207. * The new ``filter`` argument for built-in aggregates allows :ref:`adding
  208. different conditionals <conditional-aggregation>` to multiple aggregations
  209. over the same fields or relations.
  210. * Added support for expressions in :attr:`Meta.ordering
  211. <django.db.models.Options.ordering>`.
  212. * The new ``named`` parameter of :meth:`.QuerySet.values_list` allows fetching
  213. results as named tuples.
  214. * The new :class:`.FilteredRelation` class allows adding an ``ON`` clause to
  215. querysets.
  216. Pagination
  217. ~~~~~~~~~~
  218. * Added :meth:`Paginator.get_page() <django.core.paginator.Paginator.get_page>`
  219. to provide the documented pattern of handling invalid page numbers.
  220. Requests and Responses
  221. ~~~~~~~~~~~~~~~~~~~~~~
  222. * The :djadmin:`runserver` Web server supports HTTP 1.1.
  223. Templates
  224. ~~~~~~~~~
  225. * To increase the usefulness of :meth:`.Engine.get_default` in third-party
  226. apps, it now returns the first engine if multiple ``DjangoTemplates`` engines
  227. are configured in ``TEMPLATES`` rather than raising ``ImproperlyConfigured``.
  228. * Custom template tags may now accept keyword-only arguments.
  229. Tests
  230. ~~~~~
  231. * Added threading support to :class:`~django.test.LiveServerTestCase`.
  232. * Added settings that allow customizing the test tablespace parameters for
  233. Oracle: :setting:`DATAFILE_SIZE`, :setting:`DATAFILE_TMP_SIZE`,
  234. :setting:`DATAFILE_EXTSIZE`, and :setting:`DATAFILE_TMP_EXTSIZE`.
  235. Validators
  236. ~~~~~~~~~~
  237. * The new :class:`.ProhibitNullCharactersValidator` disallows the null
  238. character in the input of the :class:`~django.forms.CharField` form field
  239. and its subclasses. Null character input was observed from vulnerability
  240. scanning tools. Most databases silently discard null characters, but
  241. psycopg2 2.7+ raises an exception when trying to save a null character to
  242. a char/text field with PostgreSQL.
  243. .. _backwards-incompatible-2.0:
  244. Backwards incompatible changes in 2.0
  245. =====================================
  246. Removed support for bytestrings in some places
  247. ----------------------------------------------
  248. To support native Python 2 strings, older Django versions had to accept both
  249. bytestrings and unicode strings. Now that Python 2 support is dropped,
  250. bytestrings should only be encountered around input/output boundaries (handling
  251. of binary fields or HTTP streams, for example). You might have to update your
  252. code to limit bytestring usage to a minimum, as Django no longer accepts
  253. bytestrings in certain code paths. Python's :option:`-b` option may help detect
  254. that mistake in your code.
  255. For example, ``reverse()`` now uses ``str()`` instead of ``force_text()`` to
  256. coerce the ``args`` and ``kwargs`` it receives, prior to their placement in
  257. the URL. For bytestrings, this creates a string with an undesired ``b`` prefix
  258. as well as additional quotes (``str(b'foo')`` is ``"b'foo'"``). To adapt, call
  259. ``decode()`` on the bytestring before passing it to ``reverse()``.
  260. Database backend API
  261. --------------------
  262. This section describes changes that may be needed in third-party database
  263. backends.
  264. * The ``DatabaseOperations.datetime_cast_date_sql()``,
  265. ``datetime_cast_time_sql()``, ``datetime_trunc_sql()``,
  266. ``datetime_extract_sql()``, and ``date_interval_sql()`` methods now return
  267. only the SQL to perform the operation instead of SQL and a list of
  268. parameters.
  269. * Third-party database backends should add a ``DatabaseWrapper.display_name``
  270. attribute with the name of the database that your backend works with. Django
  271. may use it in various messages, such as in system checks.
  272. * The first argument of ``SchemaEditor._alter_column_type_sql()`` is now
  273. ``model`` rather than ``table``.
  274. * The first argument of ``SchemaEditor._create_index_name()`` is now
  275. ``table_name`` rather than ``model``.
  276. * To enable ``FOR UPDATE OF`` support, set
  277. ``DatabaseFeatures.has_select_for_update_of = True``. If the database
  278. requires that the arguments to ``OF`` be columns rather than tables, set
  279. ``DatabaseFeatures.select_for_update_of_column = True``.
  280. * To enable support for :class:`~django.db.models.expressions.Window`
  281. expressions, set ``DatabaseFeatures.supports_over_clause`` to ``True``. You
  282. may need to customize the ``DatabaseOperations.window_start_rows_start_end()``
  283. and/or ``window_start_range_start_end()`` methods.
  284. * Third-party database backends should add a
  285. ``DatabaseOperations.cast_char_field_without_max_length`` attribute with the
  286. database data type that will be used in the
  287. :class:`~django.db.models.functions.Cast` function for a ``CharField`` if the
  288. ``max_length`` argument isn't provided.
  289. * The first argument of ``DatabaseCreation._clone_test_db()`` and
  290. ``get_test_db_clone_settings()`` is now ``suffix`` rather
  291. than ``number`` (in case you want to rename the signatures in your backend
  292. for consistency). ``django.test`` also now passes those values as strings
  293. rather than as integers.
  294. * Third-party database backends should add a
  295. ``DatabaseIntrospection.get_sequences()`` method based on the stub in
  296. ``BaseDatabaseIntrospection``.
  297. Dropped support for Oracle 11.2
  298. -------------------------------
  299. The end of upstream support for Oracle 11.2 is Dec. 2020. Django 1.11 will be
  300. supported until April 2020 which almost reaches this date. Django 2.0
  301. officially supports Oracle 12.1+.
  302. Default MySQL isolation level is read committed
  303. -----------------------------------------------
  304. MySQL's default isolation level, repeatable read, may cause data loss in
  305. typical Django usage. To prevent that and for consistency with other databases,
  306. the default isolation level is now read committed. You can use the
  307. :setting:`DATABASES` setting to :ref:`use a different isolation level
  308. <mysql-isolation-level>`, if needed.
  309. :attr:`AbstractUser.last_name <django.contrib.auth.models.User.last_name>` ``max_length`` increased to 150
  310. ----------------------------------------------------------------------------------------------------------
  311. A migration for :attr:`django.contrib.auth.models.User.last_name` is included.
  312. If you have a custom user model inheriting from ``AbstractUser``, you'll need
  313. to generate and apply a database migration for your user model.
  314. If you want to preserve the 30 character limit for last names, use a custom
  315. form::
  316. from django.contrib.auth.forms import UserChangeForm
  317. class MyUserChangeForm(UserChangeForm):
  318. last_name = forms.CharField(max_length=30, required=False)
  319. If you wish to keep this restriction in the admin when editing users, set
  320. ``UserAdmin.form`` to use this form::
  321. from django.contrib.auth.admin import UserAdmin
  322. from django.contrib.auth.models import User
  323. class MyUserAdmin(UserAdmin):
  324. form = MyUserChangeForm
  325. admin.site.unregister(User)
  326. admin.site.register(User, MyUserAdmin)
  327. ``QuerySet.reverse()`` and ``last()`` are prohibited after slicing
  328. ------------------------------------------------------------------
  329. Calling ``QuerySet.reverse()`` or ``last()`` on a sliced queryset leads to
  330. unexpected results due to the slice being applied after reordering. This is
  331. now prohibited, e.g.::
  332. >>> Model.objects.all()[:2].reverse()
  333. Traceback (most recent call last):
  334. ...
  335. TypeError: Cannot reverse a query once a slice has been taken.
  336. Form fields no longer accept optional arguments as positional arguments
  337. -----------------------------------------------------------------------
  338. To help prevent runtime errors due to incorrect ordering of form field
  339. arguments, optional arguments of built-in form fields are no longer accepted
  340. as positional arguments. For example::
  341. forms.IntegerField(25, 10)
  342. raises an exception and should be replaced with::
  343. forms.IntegerField(max_value=25, min_value=10)
  344. ``call_command()`` validates the options it receives
  345. ----------------------------------------------------
  346. ``call_command()`` now validates that the argument parser of the command being
  347. called defines all of the options passed to ``call_command()``.
  348. For custom management commands that use options not created using
  349. ``parser.add_argument()``, add a ``stealth_options`` attribute on the command::
  350. class MyCommand(BaseCommand):
  351. stealth_options = ('option_name', ...)
  352. Indexes no longer accept positional arguments
  353. ---------------------------------------------
  354. For example::
  355. models.Index(['headline', '-pub_date'], 'index_name')
  356. raises an exception and should be replaced with::
  357. models.Index(fields=['headline', '-pub_date'], name='index_name')
  358. Foreign key constraints are now enabled on SQLite
  359. -------------------------------------------------
  360. This will appear as a backwards-incompatible change (``IntegrityError:
  361. FOREIGN KEY constraint failed``) if attempting to save an existing model
  362. instance that's violating a foreign key constraint.
  363. Foreign keys are now created with ``DEFERRABLE INITIALLY DEFERRED`` instead of
  364. ``DEFERRABLE IMMEDIATE``. Thus, tables may need to be rebuilt to recreate
  365. foreign keys with the new definition, particularly if you're using a pattern
  366. like this::
  367. from django.db import transaction
  368. with transaction.atomic():
  369. Book.objects.create(author_id=1)
  370. Author.objects.create(id=1)
  371. If you don't recreate the foreign key as ``DEFERRED``, the first ``create()``
  372. would fail now that foreign key constraints are enforced.
  373. Backup your database first! After upgrading to Django 2.0, you can then
  374. rebuild tables using a script similar to this::
  375. from django.apps import apps
  376. from django.db import connection
  377. for app in apps.get_app_configs():
  378. for model in app.get_models(include_auto_created=True):
  379. if model._meta.managed and not (model._meta.proxy or model._meta.swapped):
  380. for base in model.__bases__:
  381. if hasattr(base, '_meta'):
  382. base._meta.local_many_to_many = []
  383. model._meta.local_many_to_many = []
  384. with connection.schema_editor() as editor:
  385. editor._remake_table(model)
  386. This script hasn't received extensive testing and needs adaption for various
  387. cases such as multiple databases. Feel free to contribute improvements.
  388. In addition, because of a table alteration limitation of SQLite, it's prohibited
  389. to perform :class:`~django.db.migrations.operations.RenameModel` and
  390. :class:`~django.db.migrations.operations.RenameField` operations on models or
  391. fields referenced by other models in a transaction. In order to allow migrations
  392. containing these operations to be applied, you must set the
  393. ``Migration.atomic`` attribute to ``False``.
  394. Miscellaneous
  395. -------------
  396. * The ``SessionAuthenticationMiddleware`` class is removed. It provided no
  397. functionality since session authentication is unconditionally enabled in
  398. Django 1.10.
  399. * The default HTTP error handlers (``handler404``, etc.) are now callables
  400. instead of dotted Python path strings. Django favors callable references
  401. since they provide better performance and debugging experience.
  402. * :class:`~django.views.generic.base.RedirectView` no longer silences
  403. ``NoReverseMatch`` if the ``pattern_name`` doesn't exist.
  404. * When :setting:`USE_L10N` is off, :class:`~django.forms.FloatField` and
  405. :class:`~django.forms.DecimalField` now respect :setting:`DECIMAL_SEPARATOR`
  406. and :setting:`THOUSAND_SEPARATOR` during validation. For example, with the
  407. settings::
  408. USE_L10N = False
  409. USE_THOUSAND_SEPARATOR = True
  410. DECIMAL_SEPARATOR = ','
  411. THOUSAND_SEPARATOR = '.'
  412. an input of ``"1.345"`` is now converted to ``1345`` instead of ``1.345``.
  413. * Subclasses of :class:`~django.contrib.auth.models.AbstractBaseUser` are no
  414. longer required to implement ``get_short_name()`` and ``get_full_name()``.
  415. (The base implementations that raise ``NotImplementedError`` are removed.)
  416. ``django.contrib.admin`` uses these methods if implemented but doesn't
  417. require them. Third-party apps that use these methods may want to adopt a
  418. similar approach.
  419. * The ``FIRST_DAY_OF_WEEK`` and ``NUMBER_GROUPING`` format settings are now
  420. kept as integers in JavaScript and JSON i18n view outputs.
  421. * :meth:`~django.test.TransactionTestCase.assertNumQueries` now ignores
  422. connection configuration queries. Previously, if a test opened a new database
  423. connection, those queries could be included as part of the
  424. ``assertNumQueries()`` count.
  425. * The default size of the Oracle test tablespace is increased from 20M to 50M
  426. and the default autoextend size is increased from 10M to 25M.
  427. * To improve performance when streaming large result sets from the database,
  428. :meth:`.QuerySet.iterator` now fetches 2000 rows at a time instead of 100.
  429. The old behavior can be restored using the ``chunk_size`` parameter. For
  430. example::
  431. Book.objects.iterator(chunk_size=100)
  432. * Providing unknown package names in the ``packages`` argument of the
  433. :class:`~django.views.i18n.JavaScriptCatalog` view now raises ``ValueError``
  434. instead of passing silently.
  435. * A model instance's primary key now appears in the default ``Model.__str__()``
  436. method, e.g. ``Question object (1)``.
  437. * ``makemigrations`` now detects changes to the model field ``limit_choices_to``
  438. option. Add this to your existing migrations or accept an auto-generated
  439. migration for fields that use it.
  440. * Performing queries that require :ref:`automatic spatial transformations
  441. <automatic-spatial-transformations>` now raises ``NotImplementedError``
  442. on MySQL instead of silently using non-transformed geometries.
  443. * ``django.core.exceptions.DjangoRuntimeWarning`` is removed. It was only used
  444. in the cache backend as an intermediate class in ``CacheKeyWarning``'s
  445. inheritance of ``RuntimeWarning``.
  446. * Renamed ``BaseExpression._output_field`` to ``output_field``. You may need
  447. to update custom expressions.
  448. * In older versions, forms and formsets combine their ``Media`` with widget
  449. ``Media`` by concatenating the two. The combining now tries to :ref:`preserve
  450. the relative order of elements in each list <form-media-asset-order>`.
  451. ``MediaOrderConflictWarning`` is issued if the order can't be preserved.
  452. * ``django.contrib.gis.gdal.OGRException`` is removed. It's been an alias for
  453. ``GDALException`` since Django 1.8.
  454. * Support for GEOS 3.3.x is dropped.
  455. * The way data is selected for ``GeometryField`` is changed to improve
  456. performance, and in raw SQL queries, those fields must now be wrapped in
  457. ``connection.ops.select``. See the :ref:`Raw queries note<gis-raw-sql>` in
  458. the GIS tutorial for an example.
  459. .. _deprecated-features-2.0:
  460. Features deprecated in 2.0
  461. ==========================
  462. ``context`` argument of ``Field.from_db_value()`` and ``Expression.convert_value()``
  463. ------------------------------------------------------------------------------------
  464. The ``context`` argument of ``Field.from_db_value()`` and
  465. ``Expression.convert_value()`` is unused as it's always an empty dictionary.
  466. The signature of both methods is now::
  467. (self, value, expression, connection)
  468. instead of::
  469. (self, value, expression, connection, context)
  470. Support for the old signature in custom fields and expressions remains until
  471. Django 3.0.
  472. Miscellaneous
  473. -------------
  474. * The ``django.db.backends.postgresql_psycopg2`` module is deprecated in favor
  475. of ``django.db.backends.postgresql``. It's been an alias since Django 1.9.
  476. This only affects code that imports from the module directly. The
  477. ``DATABASES`` setting can still use
  478. ``'django.db.backends.postgresql_psycopg2'``, though you can simplify that by
  479. using the ``'django.db.backends.postgresql'`` name added in Django 1.9.
  480. * ``django.shortcuts.render_to_response()`` is deprecated in favor of
  481. :func:`django.shortcuts.render`. ``render()`` takes the same arguments
  482. except that it also requires a ``request``.
  483. * The ``DEFAULT_CONTENT_TYPE`` setting is deprecated. It doesn't interact well
  484. well with third-party apps and is obsolete since HTML5 has mostly superseded
  485. XHTML.
  486. * ``HttpRequest.xreadlines()`` is deprecated in favor of iterating over the
  487. request.
  488. * The ``field_name`` keyword argument to :meth:`.QuerySet.earliest` and
  489. :meth:`.QuerySet.latest` is deprecated in favor of passing the field
  490. names as arguments. Write ``.earliest('pub_date')`` instead of
  491. ``.earliest(field_name='pub_date')``.
  492. .. _removed-features-2.0:
  493. Features removed in 2.0
  494. =======================
  495. These features have reached the end of their deprecation cycle and are removed
  496. in Django 2.0.
  497. See :ref:`deprecated-features-1.9` for details on these changes, including how
  498. to remove usage of these features.
  499. * The ``weak`` argument to ``django.dispatch.signals.Signal.disconnect()`` is
  500. removed.
  501. * ``django.db.backends.base.BaseDatabaseOperations.check_aggregate_support()``
  502. is removed.
  503. * The ``django.forms.extras`` package is removed.
  504. * The ``assignment_tag`` helper is removed.
  505. * The ``host`` argument to ``SimpleTestCase.assertsRedirects()`` is removed.
  506. The compatibility layer which allows absolute URLs to be considered equal to
  507. relative ones when the path is identical is also removed.
  508. * ``Field.rel`` and ``Field.remote_field.to`` are removed.
  509. * The ``on_delete`` argument for ``ForeignKey`` and ``OneToOneField`` is now
  510. required in models and migrations. Consider squashing migrations so that you
  511. have fewer of them to update.
  512. * ``django.db.models.fields.add_lazy_relation()`` is removed.
  513. * When time zone support is enabled, database backends that don't support time
  514. zones no longer convert aware datetimes to naive values in UTC anymore when
  515. such values are passed as parameters to SQL queries executed outside of the
  516. ORM, e.g. with ``cursor.execute()``.
  517. * ``django.contrib.auth.tests.utils.skipIfCustomUser()`` is removed.
  518. * The ``GeoManager`` and ``GeoQuerySet`` classes are removed.
  519. * The ``django.contrib.gis.geoip`` module is removed.
  520. * The ``supports_recursion`` check for template loaders is removed from:
  521. * ``django.template.engine.Engine.find_template()``
  522. * ``django.template.loader_tags.ExtendsNode.find_template()``
  523. * ``django.template.loaders.base.Loader.supports_recursion()``
  524. * ``django.template.loaders.cached.Loader.supports_recursion()``
  525. * The ``load_template`` and ``load_template_sources`` template loader methods
  526. are removed.
  527. * The ``template_dirs`` argument for template loaders is removed:
  528. * ``django.template.loaders.base.Loader.get_template()``
  529. * ``django.template.loaders.cached.Loader.cache_key()``
  530. * ``django.template.loaders.cached.Loader.get_template()``
  531. * ``django.template.loaders.cached.Loader.get_template_sources()``
  532. * ``django.template.loaders.filesystem.Loader.get_template_sources()``
  533. * ``django.template.loaders.base.Loader.__call__()`` is removed.
  534. * Support for custom error views that don't accept an ``exception`` parameter
  535. is removed.
  536. * The ``mime_type`` attribute of ``django.utils.feedgenerator.Atom1Feed`` and
  537. ``django.utils.feedgenerator.RssFeed`` is removed.
  538. * The ``app_name`` argument to ``include()`` is removed.
  539. * Support for passing a 3-tuple (including ``admin.site.urls``) as the first
  540. argument to ``include()`` is removed.
  541. * Support for setting a URL instance namespace without an application namespace
  542. is removed.
  543. * ``Field._get_val_from_obj()`` is removed.
  544. * ``django.template.loaders.eggs.Loader`` is removed.
  545. * The ``current_app`` parameter to the ``contrib.auth`` function-based views is
  546. removed.
  547. * The ``callable_obj`` keyword argument to
  548. ``SimpleTestCase.assertRaisesMessage()`` is removed.
  549. * Support for the ``allow_tags`` attribute on ``ModelAdmin`` methods is
  550. removed.
  551. * The ``enclosure`` keyword argument to ``SyndicationFeed.add_item()`` is
  552. removed.
  553. * The ``django.template.loader.LoaderOrigin`` and
  554. ``django.template.base.StringOrigin`` aliases for
  555. ``django.template.base.Origin`` are removed.
  556. See :ref:`deprecated-features-1.10` for details on these changes.
  557. * The ``makemigrations --exit`` option is removed.
  558. * Support for direct assignment to a reverse foreign key or many-to-many
  559. relation is removed.
  560. * The ``get_srid()`` and ``set_srid()`` methods of
  561. ``django.contrib.gis.geos.GEOSGeometry`` are removed.
  562. * The ``get_x()``, ``set_x()``, ``get_y()``, ``set_y()``, ``get_z()``, and
  563. ``set_z()`` methods of ``django.contrib.gis.geos.Point`` are removed.
  564. * The ``get_coords()`` and ``set_coords()`` methods of
  565. ``django.contrib.gis.geos.Point`` are removed.
  566. * The ``cascaded_union`` property of ``django.contrib.gis.geos.MultiPolygon``
  567. is removed.
  568. * ``django.utils.functional.allow_lazy()`` is removed.
  569. * The ``shell --plain`` option is removed.
  570. * The ``django.core.urlresolvers`` module is removed in favor of its new
  571. location, ``django.urls``.
  572. * ``CommaSeparatedIntegerField`` is removed, except for support in historical
  573. migrations.
  574. * The template ``Context.has_key()`` method is removed.
  575. * Support for the ``django.core.files.storage.Storage.accessed_time()``,
  576. ``created_time()``, and ``modified_time()`` methods is removed.
  577. * Support for query lookups using the model name when
  578. ``Meta.default_related_name`` is set is removed.
  579. * The MySQL ``__search`` lookup is removed.
  580. * The shim for supporting custom related manager classes without a
  581. ``_apply_rel_filters()`` method is removed.
  582. * Using ``User.is_authenticated()`` and ``User.is_anonymous()`` as methods
  583. rather than properties is no longer supported.
  584. * The ``Model._meta.virtual_fields`` attribute is removed.
  585. * The keyword arguments ``virtual_only`` in ``Field.contribute_to_class()`` and
  586. ``virtual`` in ``Model._meta.add_field()`` are removed.
  587. * The ``javascript_catalog()`` and ``json_catalog()`` views are removed.
  588. * ``django.contrib.gis.utils.precision_wkt()`` is removed.
  589. * In multi-table inheritance, implicit promotion of a ``OneToOneField`` to a
  590. ``parent_link`` is removed.
  591. * Support for ``Widget._format_value()`` is removed.
  592. * ``FileField`` methods ``get_directory_name()`` and ``get_filename()`` are
  593. removed.
  594. * The ``mark_for_escaping()`` function and the classes it uses: ``EscapeData``,
  595. ``EscapeBytes``, ``EscapeText``, ``EscapeString``, and ``EscapeUnicode`` are
  596. removed.
  597. * The ``escape`` filter now uses ``django.utils.html.conditional_escape()``.
  598. * ``Manager.use_for_related_fields`` is removed.
  599. * Model ``Manager`` inheritance follows MRO inheritance rules. The requirement
  600. to use ``Meta.manager_inheritance_from_future`` to opt-in to the behavior is
  601. removed.
  602. * Support for old-style middleware using ``settings.MIDDLEWARE_CLASSES`` is
  603. removed.