1.6.txt 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. ============================================
  2. Django 1.6 release notes - UNDER DEVELOPMENT
  3. ============================================
  4. Welcome to Django 1.6!
  5. These release notes cover the `new features`_, as well as some `backwards
  6. incompatible changes`_ you'll want to be aware of when upgrading from Django
  7. 1.5 or older versions. We've also dropped some features, which are detailed in
  8. :doc:`our deprecation plan </internals/deprecation>`, and we've `begun the
  9. deprecation process for some features`_.
  10. .. _`new features`: `What's new in Django 1.6`_
  11. .. _`backwards incompatible changes`: `Backwards incompatible changes in 1.6`_
  12. .. _`begun the deprecation process for some features`: `Features deprecated in 1.6`_
  13. What's new in Django 1.6
  14. ========================
  15. Simplified default project and app templates
  16. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  17. The default templates used by :djadmin:`startproject` and :djadmin:`startapp`
  18. have been simplified and modernized. The :doc:`admin
  19. </ref/contrib/admin/index>` is now enabled by default in new projects; the
  20. :doc:`sites </ref/contrib/sites>` framework no longer is. :ref:`Language
  21. detection <how-django-discovers-language-preference>` and :ref:`clickjacking
  22. prevention <clickjacking-prevention>` are turned on.
  23. If the default templates don't suit your tastes, you can use :ref:`custom
  24. project and app templates <custom-app-and-project-templates>`.
  25. Improved transaction management
  26. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  27. Django's transaction management was overhauled. Database-level autocommit is
  28. now turned on by default. This makes transaction handling more explicit and
  29. should improve performance. The existing APIs were deprecated, and new APIs
  30. were introduced, as described in the :doc:`transaction management docs
  31. </topics/db/transactions>`.
  32. Please review carefully the list of :ref:`known backwards-incompatibilities
  33. <transactions-upgrading-from-1.5>` to determine if you need to make changes in
  34. your code.
  35. Persistent database connections
  36. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  37. Django now supports reusing the same database connection for several requests.
  38. This avoids the overhead of re-establishing a connection at the beginning of
  39. each request.
  40. By default, database connections will kept open for 10 minutes. This behavior
  41. is controlled by the :setting:`CONN_MAX_AGE` setting. To restore the previous
  42. behavior of closing the connection at the end of each request, set
  43. :setting:`CONN_MAX_AGE` to ``0``. See :ref:`persistent-database-connections`
  44. for details.
  45. Time zone aware aggregation
  46. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  47. The support for :doc:`time zones </topics/i18n/timezones>` introduced in
  48. Django 1.4 didn't work well with :meth:`QuerySet.dates()
  49. <django.db.models.query.QuerySet.dates>`: aggregation was always performed in
  50. UTC. This limitation was lifted in Django 1.6. Use :meth:`QuerySet.datetimes()
  51. <django.db.models.query.QuerySet.datetimes>` to perform time zone aware
  52. aggregation on a :class:`~django.db.models.DateTimeField`.
  53. Support for savepoints in SQLite
  54. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  55. Django 1.6 adds support for savepoints in SQLite, with some :ref:`limitations
  56. <savepoints-in-sqlite>`.
  57. ``BinaryField`` model field
  58. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  59. A new :class:`django.db.models.BinaryField` model field allows to store raw
  60. binary data in the database.
  61. Minor features
  62. ~~~~~~~~~~~~~~
  63. * Authentication backends can raise ``PermissionDenied`` to immediately fail
  64. the authentication chain.
  65. * The HttpOnly flag can be set on the CSRF cookie with
  66. :setting:`CSRF_COOKIE_HTTPONLY`.
  67. * The ``assertQuerysetEqual()`` now checks for undefined order and raises
  68. ``ValueError`` if undefined order is spotted. The order is seen as
  69. undefined if the given ``QuerySet`` isn't ordered and there are more than
  70. one ordered values to compare against.
  71. * Added :meth:`~django.db.models.query.QuerySet.earliest` for symmetry with
  72. :meth:`~django.db.models.query.QuerySet.latest`.
  73. * In addition to :lookup:`year`, :lookup:`month` and :lookup:`day`, the ORM
  74. now supports :lookup:`hour`, :lookup:`minute` and :lookup:`second` lookups.
  75. * Django now wraps all PEP-249 exceptions.
  76. * The default widgets for :class:`~django.forms.EmailField`,
  77. :class:`~django.forms.URLField`, :class:`~django.forms.IntegerField`,
  78. :class:`~django.forms.FloatField` and :class:`~django.forms.DecimalField` use
  79. the new type attributes available in HTML5 (type='email', type='url',
  80. type='number'). Note that due to erratic support of the ``number`` input type
  81. with localized numbers in current browsers, Django only uses it when numeric
  82. fields are not localized.
  83. * The ``number`` argument for :ref:`lazy plural translations
  84. <lazy-plural-translations>` can be provided at translation time rather than
  85. at definition time.
  86. * For custom management commands: Verification of the presence of valid
  87. settings in commands that ask for it by using the
  88. :attr:`~django.core.management.BaseCommand.can_import_settings` internal
  89. option is now performed independently from handling of the locale that
  90. should be active during the execution of the command. The latter can now be
  91. influenced by the new
  92. :attr:`~django.core.management.BaseCommand.leave_locale_alone` internal
  93. option. See :ref:`management-commands-and-locales` for more details.
  94. * The :attr:`~django.views.generic.edit.DeletionMixin.success_url` of
  95. :class:`~django.views.generic.edit.DeletionMixin` is now interpolated with
  96. its ``object``\'s ``__dict__``.
  97. * :class:`~django.http.HttpResponseRedirect` and
  98. :class:`~django.http.HttpResponsePermanentRedirect` now provide an ``url``
  99. attribute (equivalent to the URL the response will redirect to).
  100. * The ``MemcachedCache`` cache backend now uses the latest :mod:`pickle`
  101. protocol available.
  102. * Added :class:`~django.contrib.messages.views.SuccessMessageMixin` which
  103. provides a ``success_message`` attribute for
  104. :class:`~django.view.generic.edit.FormView` based classes.
  105. * Added the :attr:`django.db.models.ForeignKey.db_constraint` and
  106. :attr:`django.db.models.ManyToManyField.db_constraint` options.
  107. * The jQuery library embedded in the admin has been upgraded to version 1.9.1.
  108. * Syndication feeds (:mod:`django.contrib.syndication`) can now pass extra
  109. context through to feed templates using a new `Feed.get_context_data()`
  110. callback.
  111. * The admin list columns have a ``column-<field_name>`` class in the HTML
  112. so the columns header can be styled with CSS, e.g. to set a column width.
  113. * The isolation level can be customized under PostgreSQL.
  114. * The :ttag:`blocktrans` template tag now respects
  115. :setting:`TEMPLATE_STRING_IF_INVALID` for variables not present in the
  116. context, just like other template constructs.
  117. * SimpleLazyObjects will now present more helpful representations in shell
  118. debugging situations.
  119. * Generic :class:`~django.contrib.gis.db.models.GeometryField` is now editable
  120. with the OpenLayers widget in the admin.
  121. * The :meth:`Model.save() <django.db.models.Model.save()>` will do
  122. ``UPDATE`` - if not updated - ``INSERT`` instead of ``SELECT`` - if not
  123. found ``INSERT`` else ``UPDATE`` in case the model's primary key is set.
  124. * The documentation contains a :doc:`deployment checklist
  125. </howto/deployment/checklist>`.
  126. * The :djadmin:`diffsettings` comand gained a ``--all`` option.
  127. * :func:`django.forms.fields.Field.__init__` now calls ``super()``, allowing
  128. field mixins to implement ``__init__()`` methods that will reliably be
  129. called.
  130. * The ``validate_max`` parameter was added to ``BaseFormSet`` and
  131. :func:`~django.forms.formsets.formset_factory`, and ``ModelForm`` and inline
  132. versions of the same. The behavior of validation for formsets with
  133. ``max_num`` was clarified. The previously undocumented behavior that
  134. hardened formsets against memory exhaustion attacks was documented,
  135. and the undocumented limit of the higher of 1000 or ``max_num`` forms
  136. was changed so it is always 1000 more than ``max_num``.
  137. Backwards incompatible changes in 1.6
  138. =====================================
  139. .. warning::
  140. In addition to the changes outlined in this section, be sure to review the
  141. :doc:`deprecation plan </internals/deprecation>` for any features that
  142. have been removed. If you haven't updated your code within the
  143. deprecation timeline for a given feature, its removal may appear as a
  144. backwards incompatible change.
  145. New transaction management model
  146. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  147. Behavior changes
  148. ^^^^^^^^^^^^^^^^
  149. Database-level autocommit is enabled by default in Django 1.6. While this
  150. doesn't change the general spirit of Django's transaction management, there
  151. are a few known backwards-incompatibities, described in the :ref:`transaction
  152. management docs <transactions-upgrading-from-1.5>`. You should review your
  153. code to determine if you're affected.
  154. Savepoints and ``assertNumQueries``
  155. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  156. The changes in transaction management may result in additional statements to
  157. create, release or rollback savepoints. This is more likely to happen with
  158. SQLite, since it didn't support savepoints until this release.
  159. If tests using :meth:`~django.test.TestCase.assertNumQueries` fail because of
  160. a higher number of queries than expected, check that the extra queries are
  161. related to savepoints, and adjust the expected number of queries accordingly.
  162. Autocommit option for PostgreSQL
  163. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  164. In previous versions, database-level autocommit was only an option for
  165. PostgreSQL, and it was disabled by default. This option is now :ref:`ignored
  166. <postgresql-autocommit-mode>` and can be removed.
  167. Addition of ``QuerySet.datetimes()``
  168. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  169. When the :doc:`time zone support </topics/i18n/timezones>` added in Django 1.4
  170. was active, :meth:`QuerySet.dates() <django.db.models.query.QuerySet.dates>`
  171. lookups returned unexpected results, because the aggregation was performed in
  172. UTC. To fix this, Django 1.6 introduces a new API, :meth:`QuerySet.datetimes()
  173. <django.db.models.query.QuerySet.datetimes>`. This requires a few changes in
  174. your code.
  175. ``QuerySet.dates()`` returns ``date`` objects
  176. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  177. :meth:`QuerySet.dates() <django.db.models.query.QuerySet.dates>` now returns a
  178. list of :class:`~datetime.date`. It used to return a list of
  179. :class:`~datetime.datetime`.
  180. :meth:`QuerySet.datetimes() <django.db.models.query.QuerySet.datetimes>`
  181. returns a list of :class:`~datetime.datetime`.
  182. ``QuerySet.dates()`` no longer usable on ``DateTimeField``
  183. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  184. :meth:`QuerySet.dates() <django.db.models.query.QuerySet.dates>` raises an
  185. error if it's used on :class:`~django.db.models.DateTimeField` when time
  186. zone support is active. Use :meth:`QuerySet.datetimes()
  187. <django.db.models.query.QuerySet.datetimes>` instead.
  188. ``date_hierarchy`` requires time zone definitions
  189. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  190. The :attr:`~django.contrib.admin.ModelAdmin.date_hierarchy` feature of the
  191. admin now relies on :meth:`QuerySet.datetimes()
  192. <django.db.models.query.QuerySet.datetimes>` when it's used on a
  193. :class:`~django.db.models.DateTimeField`.
  194. This requires time zone definitions in the database when :setting:`USE_TZ` is
  195. ``True``. :ref:`Learn more <database-time-zone-definitions>`.
  196. ``date_list`` in generic views requires time zone definitions
  197. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  198. For the same reason, accessing ``date_list`` in the context of a date-based
  199. generic view requires time zone definitions in the database when the view is
  200. based on a :class:`~django.db.models.DateTimeField` and :setting:`USE_TZ` is
  201. ``True``. :ref:`Learn more <database-time-zone-definitions>`.
  202. New lookups may clash with model fields
  203. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  204. Django 1.6 introduces ``hour``, ``minute``, and ``second`` lookups on
  205. :class:`~django.db.models.DateTimeField`. If you had model fields called
  206. ``hour``, ``minute``, or ``second``, the new lookups will clash with you field
  207. names. Append an explicit :lookup:`exact` lookup if this is an issue.
  208. Persistent database connections
  209. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  210. Connection setup not repeated for each request
  211. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  212. When Django establishes a connection to the database, it sets up appropriate
  213. parameters, depending on the backend being used. Since `persistent database
  214. connections <persistent-database-connections>`_ are enabled by default in
  215. Django 1.6, this setup isn't repeated at every request any more. If you
  216. modifiy parameters such as the connection's isolation level or time zone, you
  217. should either restore Django's defaults at the end of each request, force an
  218. appropriate value at the beginning of each request, or disable persistent
  219. connections.
  220. Translations and comments in templates
  221. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  222. Extraction of translations after comments
  223. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  224. Extraction of translatable literals from templates with the
  225. :djadmin:`makemessages` command now correctly detects i18n constructs when
  226. they are located after a ``{#`` / ``#}``-type comment on the same line. E.g.:
  227. .. code-block:: html+django
  228. {# A comment #}{% trans "This literal was incorrectly ignored. Not anymore" %}
  229. Location of translator comments
  230. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  231. Validation of the placement of :ref:`translator-comments-in-templates`
  232. specified using ``{#`` / ``#}`` is now stricter. All translator comments not
  233. located at the end of their respective lines in a template are ignored and a
  234. warning is generated by :djadmin:`makemessages` when it finds them. E.g.:
  235. .. code-block:: html+django
  236. {# Translators: This is ignored #}{% trans "Translate me" %}
  237. {{ title }}{# Translators: Extracted and associated with 'Welcome' below #}
  238. <h1>{% trans "Welcome" %}</h1>
  239. Quoting in :func:`~django.core.urlresolvers.reverse`
  240. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  241. When reversing URLs, Django didn't apply :func:`~django.utils.http.urlquote`
  242. to arguments before interpolating them in URL patterns. This bug is fixed in
  243. Django 1.6. If you worked around this bug by applying URL quoting before
  244. passing arguments to :func:`~django.core.urlresolvers.reverse`, this may
  245. result in double-quoting. If this happens, simply remove the URL quoting from
  246. your code.
  247. Storage of IP addresses in the comments app
  248. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  249. The :doc:`comments </ref/contrib/comments/index>` app now uses a
  250. ``GenericIPAddressField`` for storing commenters' IP addresses, to support
  251. comments submitted from IPv6 addresses. Until now, it stored them in an
  252. ``IPAddressField``, which is only meant to support IPv4. When saving a comment
  253. made from an IPv6 address, the address would be silently truncated on MySQL
  254. databases, and raise an exception on Oracle. You will need to change the
  255. column type in your database to benefit from this change.
  256. For MySQL, execute this query on your project's database:
  257. .. code-block:: sql
  258. ALTER TABLE django_comments MODIFY ip_address VARCHAR(39);
  259. For Oracle, execute this query:
  260. .. code-block:: sql
  261. ALTER TABLE DJANGO_COMMENTS MODIFY (ip_address VARCHAR2(39));
  262. If you do not apply this change, the behaviour is unchanged: on MySQL, IPv6
  263. addresses are silently truncated; on Oracle, an exception is generated. No
  264. database change is needed for SQLite or PostgreSQL databases.
  265. Miscellaneous
  266. ~~~~~~~~~~~~~
  267. * The ``django.db.models.query.EmptyQuerySet`` can't be instantiated any more -
  268. it is only usable as a marker class for checking if
  269. :meth:`~django.db.models.query.QuerySet.none` has been called:
  270. ``isinstance(qs.none(), EmptyQuerySet)``
  271. * If your CSS/Javascript code used to access HTML input widgets by type, you
  272. should review it as ``type='text'`` widgets might be now output as
  273. ``type='email'``, ``type='url'`` or ``type='number'`` depending on their
  274. corresponding field type.
  275. Features deprecated in 1.6
  276. ==========================
  277. Transaction management APIs
  278. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  279. Transaction management was completely overhauled in Django 1.6, and the
  280. current APIs are deprecated:
  281. - ``django.middleware.transaction.TransactionMiddleware``
  282. - ``django.db.transaction.autocommit``
  283. - ``django.db.transaction.commit_on_success``
  284. - ``django.db.transaction.commit_manually``
  285. - the ``TRANSACTIONS_MANAGED`` setting
  286. The reasons for this change and the upgrade path are described in the
  287. :ref:`transactions documentation <transactions-upgrading-from-1.5>`.
  288. ``django.contrib.comments``
  289. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  290. Django's comment framework has been deprecated and is no longer supported. It
  291. will be available in Django 1.6 and 1.7, and removed in Django 1.8. Most users
  292. will be better served with a custom solution, or a hosted product like Disqus__.
  293. The code formerly known as ``django.contrib.comments`` is `still available
  294. in an external repository`__.
  295. __ https://disqus.com/
  296. __ https://github.com/django/django-contrib-comments
  297. Support for PostgreSQL versions older than 8.4
  298. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  299. The end of upstream support periods was reached in December 2011 for
  300. PostgreSQL 8.2 and in February 2013 for 8.3. As a consequence, Django 1.6 sets
  301. 8.4 as the minimum PostgreSQL version it officially supports.
  302. You're strongly encouraged to use the most recent version of PostgreSQL
  303. available, because of performance improvements and to take advantage of the
  304. native streaming replication available in PostgreSQL 9.x.
  305. Changes to :ttag:`cycle` and :ttag:`firstof`
  306. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  307. The template system generally escapes all variables to avoid XSS attacks.
  308. However, due to an accident of history, the :ttag:`cycle` and :ttag:`firstof`
  309. tags render their arguments as-is.
  310. Django 1.6 starts a process to correct this inconsistency. The ``future``
  311. template library provides alternate implementations of :ttag:`cycle` and
  312. :ttag:`firstof` that autoescape their inputs. If you're using these tags,
  313. you're encourage to include the following line at the top of your templates to
  314. enable the new behavior::
  315. {% load cycle from future %}
  316. or::
  317. {% load firstof from future %}
  318. The tags implementing the old behavior have been deprecated, and in Django
  319. 1.8, the old behavior will be replaced with the new behavior. To ensure
  320. compatibility with future versions of Django, existing templates should be
  321. modified to use the ``future`` versions.
  322. If necessary, you can temporarily disable auto-escaping with
  323. :func:`~django.utils.safestring.mark_safe` or :ttag:`{% autoescape off %}
  324. <autoescape>`.
  325. ``SEND_BROKEN_LINK_EMAILS`` setting
  326. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  327. :class:`~django.middleware.common.CommonMiddleware` used to provide basic
  328. reporting of broken links by email when ``SEND_BROKEN_LINK_EMAILS`` is set to
  329. ``True``.
  330. Because of intractable ordering problems between
  331. :class:`~django.middleware.common.CommonMiddleware` and
  332. :class:`~django.middleware.locale.LocaleMiddleware`, this feature was split
  333. out into a new middleware:
  334. :class:`~django.middleware.common.BrokenLinkEmailsMiddleware`.
  335. If you're relying on this feature, you should add
  336. ``'django.middleware.common.BrokenLinkEmailsMiddleware'`` to your
  337. :setting:`MIDDLEWARE_CLASSES` setting and remove ``SEND_BROKEN_LINK_EMAILS``
  338. from your settings.
  339. ``_has_changed`` method on widgets
  340. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  341. If you defined your own form widgets and defined the ``_has_changed`` method
  342. on a widget, you should now define this method on the form field itself.
  343. ``module_name`` model meta attribute
  344. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  345. ``Model._meta.module_name`` was renamed to ``model_name``. Despite being a
  346. private API, it will go through a regular deprecation path.
  347. ``get_query_set`` and similar methods renamed to ``get_queryset``
  348. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  349. Methods that return a ``QuerySet`` such as ``Manager.get_query_set`` or
  350. ``ModelAdmin.queryset`` have been renamed to ``get_queryset``.
  351. ``shortcut`` view and URLconf
  352. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  353. The ``shortcut`` view was moved from ``django.views.defaults`` to
  354. ``django.contrib.contenttypes.views`` shortly after the 1.0 release, but the
  355. old location was never deprecated. This oversight was corrected in Django 1.6
  356. and you should now use the new location.
  357. The URLconf ``django.conf.urls.shortcut`` was also deprecated. If you're
  358. including it in an URLconf, simply replace::
  359. (r'^prefix/', include('django.conf.urls.shortcut')),
  360. with::
  361. (r'^prefix/(?P<content_type_id>\d+)/(?P<object_id>.*)/$', 'django.contrib.contenttypes.views.shortcut'),