1.5.txt 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. ============================================
  2. Django 1.5 release notes - UNDER DEVELOPMENT
  3. ============================================
  4. These release notes cover the `new features`_, as well
  5. as some `backwards incompatible changes`_ you'll want to be aware of
  6. when upgrading from Django 1.4 or older versions. We've also dropped some
  7. features, which are detailed in :doc:`our deprecation plan
  8. </internals/deprecation>`, and we've `begun the deprecation process for some
  9. features`_.
  10. .. _`new features`: `What's new in Django 1.5`_
  11. .. _`backwards incompatible changes`: `Backwards incompatible changes in 1.5`_
  12. .. _`begun the deprecation process for some features`: `Features deprecated in 1.5`_
  13. Python compatibility
  14. ====================
  15. Django 1.5 has dropped support for Python 2.5. Python 2.6.5 is now the minimum
  16. required Python version. Django is tested and supported on Python 2.6 and
  17. 2.7.
  18. This change should affect only a small number of Django users, as most
  19. operating-system vendors today are shipping Python 2.6 or newer as their default
  20. version. If you're still using Python 2.5, however, you'll need to stick to
  21. Django 1.4 until you can upgrade your Python version. Per :doc:`our support policy
  22. </internals/release-process>`, Django 1.4 will continue to receive security
  23. support until the release of Django 1.6.
  24. Django 1.5 does not run on a Jython final release, because Jython's latest release
  25. doesn't currently support Python 2.6. However, Jython currently does offer an alpha
  26. release featuring 2.7 support.
  27. What's new in Django 1.5
  28. ========================
  29. Configurable User model
  30. ~~~~~~~~~~~~~~~~~~~~~~~
  31. In Django 1.5, you can now use your own model as the store for user-related
  32. data. If your project needs a username with more than 30 characters, or if
  33. you want to store usernames in a format other than first name/last name, or
  34. you want to put custom profile information onto your User object, you can
  35. now do so.
  36. If you have a third-party reusable application that references the User model,
  37. you may need to make some changes to the way you reference User instances. You
  38. should also document any specific features of the User model that your
  39. application relies upon.
  40. See the :ref:`documentation on custom User models <auth-custom-user>` for
  41. more details.
  42. Support for saving a subset of model's fields
  43. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  44. The method :meth:`Model.save() <django.db.models.Model.save()>` has a new
  45. keyword argument ``update_fields``. By using this argument it is possible to
  46. save only a select list of model's fields. This can be useful for performance
  47. reasons or when trying to avoid overwriting concurrent changes.
  48. Deferred instances (those loaded by .only() or .defer()) will automatically
  49. save just the loaded fields. If any field is set manually after load, that
  50. field will also get updated on save.
  51. See the :meth:`Model.save() <django.db.models.Model.save()>` documentation for
  52. more details.
  53. Caching of related model instances
  54. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  55. When traversing relations, the ORM will avoid re-fetching objects that were
  56. previously loaded. For example, with the tutorial's models::
  57. >>> first_poll = Poll.objects.all()[0]
  58. >>> first_choice = first_poll.choice_set.all()[0]
  59. >>> first_choice.poll is first_poll
  60. True
  61. In Django 1.5, the third line no longer triggers a new SQL query to fetch
  62. ``first_choice.poll``; it was set by the second line.
  63. For one-to-one relationships, both sides can be cached. For many-to-one
  64. relationships, only the single side of the relationship can be cached. This
  65. is particularly helpful in combination with ``prefetch_related``.
  66. ``{% verbatim %}`` template tag
  67. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  68. To make it easier to deal with javascript templates which collide with Django's
  69. syntax, you can now use the :ttag:`verbatim` block tag to avoid parsing the
  70. tag's content.
  71. Retrieval of ``ContentType`` instances associated with proxy models
  72. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  73. The methods :meth:`ContentTypeManager.get_for_model() <django.contrib.contenttypes.models.ContentTypeManager.get_for_model()>`
  74. and :meth:`ContentTypeManager.get_for_models() <django.contrib.contenttypes.models.ContentTypeManager.get_for_models()>`
  75. have a new keyword argument – respectively ``for_concrete_model`` and ``for_concrete_models``.
  76. By passing ``False`` using this argument it is now possible to retreive the
  77. :class:`ContentType <django.contrib.contenttypes.models.ContentType>`
  78. associated with proxy models.
  79. New ``view`` variable in class-based views context
  80. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  81. In all :doc:`generic class-based views </topics/class-based-views/index>`
  82. (or any class-based view inheriting from ``ContextMixin``), the context dictionary
  83. contains a ``view`` variable that points to the ``View`` instance.
  84. GeoDjango
  85. ~~~~~~~~~
  86. * :class:`~django.contrib.gis.geos.LineString` and
  87. :class:`~django.contrib.gis.geos.MultiLineString` GEOS objects now support the
  88. :meth:`~django.contrib.gis.geos.GEOSGeometry.interpolate()` and
  89. :meth:`~django.contrib.gis.geos.GEOSGeometry.project()` methods
  90. (so-called linear referencing).
  91. * The wkb and hex properties of `GEOSGeometry` objects preserve the Z dimension.
  92. * Support for PostGIS 2.0 has been added and support for GDAL < 1.5 has been
  93. dropped.
  94. Minor features
  95. ~~~~~~~~~~~~~~
  96. Django 1.5 also includes several smaller improvements worth noting:
  97. * The template engine now interprets ``True``, ``False`` and ``None`` as the
  98. corresponding Python objects.
  99. * :mod:`django.utils.timezone` provides a helper for converting aware
  100. datetimes between time zones. See :func:`~django.utils.timezone.localtime`.
  101. * The generic views support OPTIONS requests.
  102. * Management commands do not raise ``SystemExit`` any more when called by code
  103. from :ref:`call_command <call-command>`. Any exception raised by the command
  104. (mostly :ref:`CommandError <ref-command-exceptions>`) is propagated.
  105. * The dumpdata management command outputs one row at a time, preventing
  106. out-of-memory errors when dumping large datasets.
  107. * In the localflavor for Canada, "pq" was added to the acceptable codes for
  108. Quebec. It's an old abbreviation.
  109. * The :ref:`receiver <connecting-receiver-functions>` decorator is now able to
  110. connect to more than one signal by supplying a list of signals.
  111. * In the admin, you can now filter users by groups which they are members of.
  112. * :meth:`QuerySet.bulk_create()
  113. <django.db.models.query.QuerySet.bulk_create>` now has a batch_size
  114. argument. By default the batch_size is unlimited except for SQLite where
  115. single batch is limited so that 999 parameters per query isn't exceeded.
  116. * The :setting:`LOGIN_URL` and :setting:`LOGIN_REDIRECT_URL` settings now also
  117. accept view function names and
  118. :ref:`named URL patterns <naming-url-patterns>`. This allows you to reduce
  119. configuration duplication. More information can be found in the
  120. :func:`~django.contrib.auth.decorators.login_required` documentation.
  121. * Django now provides a mod_wsgi :doc:`auth handler
  122. </howto/deployment/wsgi/apache-auth>`.
  123. * The :meth:`QuerySet.delete() <django.db.models.query.QuerySet.delete>`
  124. and :meth:`Model.delete() <django.db.models.Model.delete()>` can now take
  125. fast-path in some cases. The fast-path allows for less queries and less
  126. objects fetched into memory. See :meth:`QuerySet.delete()
  127. <django.db.models.query.QuerySet.delete>` for details.
  128. * An instance of :class:`~django.core.urlresolvers.ResolverMatch` is stored on
  129. the request as ``resolver_match``.
  130. * By default, all logging messages reaching the `django` logger when
  131. :setting:`DEBUG` is `True` are sent to the console (unless you redefine the
  132. logger in your :setting:`LOGGING` setting).
  133. * :ref:`F() expressions <query-expressions>` now support comparison operations
  134. and inversion, expanding the types of expressions that can be passed to the
  135. database.
  136. * When using :class:`~django.template.RequestContext`, it is now possible to
  137. look up permissions by using ``{% if 'someapp.someperm' in perms %}``
  138. in templates.
  139. * It's not required any more to have ``404.html`` and ``500.html`` templates in
  140. the root templates directory. Django will output some basic error messages for
  141. both situations when those templates are not found. Of course, it's still
  142. recommended as good practice to provide those templates in order to present
  143. pretty error pages to the user.
  144. Backwards incompatible changes in 1.5
  145. =====================================
  146. .. warning::
  147. In addition to the changes outlined in this section, be sure to review the
  148. :doc:`deprecation plan </internals/deprecation>` for any features that
  149. have been removed. If you haven't updated your code within the
  150. deprecation timeline for a given feature, its removal may appear as a
  151. backwards incompatible change.
  152. Context in year archive class-based views
  153. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  154. For consistency with the other date-based generic views,
  155. :class:`~django.views.generic.dates.YearArchiveView` now passes ``year`` in
  156. the context as a :class:`datetime.date` rather than a string. If you are
  157. using ``{{ year }}`` in your templates, you must replace it with ``{{
  158. year|date:"Y" }}``.
  159. ``next_year`` and ``previous_year`` were also added in the context. They are
  160. calculated according to ``allow_empty`` and ``allow_future``.
  161. Context in year and month archive class-based views
  162. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  163. :class:`~django.views.generic.dates.YearArchiveView` and
  164. :class:`~django.views.generic.dates.MonthArchiveView` were documented to
  165. provide a ``date_list`` sorted in ascending order in the context, like their
  166. function-based predecessors, but it actually was in descending order. In 1.5,
  167. the documented order was restored. You may want to add (or remove) the
  168. ``reversed`` keyword when you're iterating on ``date_list`` in a template::
  169. {% for date in date_list reversed %}
  170. :class:`~django.views.generic.dates.ArchiveIndexView` still provides a
  171. ``date_list`` in descending order.
  172. Context in TemplateView
  173. ~~~~~~~~~~~~~~~~~~~~~~~
  174. For consistency with the design of the other generic views,
  175. :class:`~django.views.generic.base.TemplateView` no longer passes a ``params``
  176. dictionary into the context, instead passing the variables from the URLconf
  177. directly into the context.
  178. OPTIONS, PUT and DELETE requests in the test client
  179. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  180. Unlike GET and POST, these HTTP methods aren't implemented by web browsers.
  181. Rather, they're used in APIs, which transfer data in various formats such as
  182. JSON or XML. Since such requests may contain arbitrary data, Django doesn't
  183. attempt to decode their body.
  184. However, the test client used to build a query string for OPTIONS and DELETE
  185. requests like for GET, and a request body for PUT requests like for POST. This
  186. encoding was arbitrary and inconsistent with Django's behavior when it
  187. receives the requests, so it was removed in Django 1.5.
  188. If you were using the ``data`` parameter in an OPTIONS or a DELETE request,
  189. you must convert it to a query string and append it to the ``path`` parameter.
  190. If you were using the ``data`` parameter in a PUT request without a
  191. ``content_type``, you must encode your data before passing it to the test
  192. client and set the ``content_type`` argument.
  193. .. _simplejson-incompatibilities:
  194. System version of :mod:`simplejson` no longer used
  195. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  196. :ref:`As explained below <simplejson-deprecation>`, Django 1.5 deprecates
  197. :mod:`django.utils.simplejson` in favor of Python 2.6's built-in :mod:`json`
  198. module. In theory, this change is harmless. Unfortunately, because of
  199. incompatibilities between versions of :mod:`simplejson`, it may trigger errors
  200. in some circumstances.
  201. JSON-related features in Django 1.4 always used :mod:`django.utils.simplejson`.
  202. This module was actually:
  203. - A system version of :mod:`simplejson`, if one was available (ie. ``import
  204. simplejson`` works), if it was more recent than Django's built-in copy or it
  205. had the C speedups, or
  206. - The :mod:`json` module from the standard library, if it was available (ie.
  207. Python 2.6 or greater), or
  208. - A built-in copy of version 2.0.7 of :mod:`simplejson`.
  209. In Django 1.5, those features use Python's :mod:`json` module, which is based
  210. on version 2.0.9 of :mod:`simplejson`.
  211. There are no known incompatibilities between Django's copy of version 2.0.7 and
  212. Python's copy of version 2.0.9. However, there are some incompatibilities
  213. between other versions of :mod:`simplejson`:
  214. - While the :mod:`simplejson` API is documented as always returning unicode
  215. strings, the optional C implementation can return a byte string. This was
  216. fixed in Python 2.7.
  217. - :class:`simplejson.JSONEncoder` gained a ``namedtuple_as_object`` keyword
  218. argument in version 2.2.
  219. More information on these incompatibilities is available in `ticket #18023`_.
  220. The net result is that, if you have installed :mod:`simplejson` and your code
  221. uses Django's serialization internals directly -- for instance
  222. :class:`django.core.serializers.json.DjangoJSONEncoder`, the switch from
  223. :mod:`simplejson` to :mod:`json` could break your code. (In general, changes to
  224. internals aren't documented; we're making an exception here.)
  225. At this point, the maintainers of Django believe that using :mod:`json` from
  226. the standard library offers the strongest guarantee of backwards-compatibility.
  227. They recommend to use it from now on.
  228. .. _ticket #18023: https://code.djangoproject.com/ticket/18023#comment:10
  229. String types of hasher method parameters
  230. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  231. If you have written a :ref:`custom password hasher <auth_password_storage>`,
  232. your ``encode()``, ``verify()`` or ``safe_summary()`` methods should accept
  233. Unicode parameters (``password``, ``salt`` or ``encoded``). If any of the
  234. hashing methods need byte strings, you can use the
  235. :func:`~django.utils.encoding.force_bytes` utility to encode the strings.
  236. Validation of previous_page_number and next_page_number
  237. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  238. When using :doc:`object pagination </topics/pagination>`,
  239. the ``previous_page_number()`` and ``next_page_number()`` methods of the
  240. :class:`~django.core.paginator.Page` object did not check if the returned
  241. number was inside the existing page range.
  242. It does check it now and raises an :exc:`InvalidPage` exception when the number
  243. is either too low or too high.
  244. Behavior of autocommit database option on PostgreSQL changed
  245. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  246. PostgreSQL's autocommit option didn't work as advertised previously. It did
  247. work for single transaction block, but after the first block was left the
  248. autocommit behavior was never restored. This bug is now fixed in 1.5. While
  249. this is only a bug fix, it is worth checking your applications behavior if
  250. you are using PostgreSQL together with the autocommit option.
  251. Session not saved on 500 responses
  252. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  253. Django's session middleware will skip saving the session data if the
  254. response's status code is 500.
  255. Email checks on failed admin login
  256. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  257. Prior to Django 1.5, if you attempted to log into the admin interface and
  258. mistakenly used your email address instead of your username, the admin
  259. interface would provide a warning advising that your email address was
  260. not your username. In Django 1.5, the introduction of
  261. :ref:`custom User models <auth-custom-user>` has required the removal of this
  262. warning. This doesn't change the login behavior of the admin site; it only
  263. affects the warning message that is displayed under one particular mode of
  264. login failure.
  265. Changes in tests execution
  266. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  267. Some changes have been introduced in the execution of tests that might be
  268. backward-incompatible for some testing setups:
  269. Database flushing in ``django.test.TransactionTestCase``
  270. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  271. Previously, the test database was truncated *before* each test run in a
  272. :class:`~django.test.TransactionTestCase`.
  273. In order to be able to run unit tests in any order and to make sure they are
  274. always isolated from each other, :class:`~django.test.TransactionTestCase` will
  275. now reset the database *after* each test run instead.
  276. No more implict DB sequences reset
  277. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  278. :class:`~django.test.TransactionTestCase` tests used to reset primary key
  279. sequences automatically together with the database flushing actions described
  280. above.
  281. This has been changed so no sequences are implicitly reset. This can cause
  282. :class:`~django.test.TransactionTestCase` tests that depend on hard-coded
  283. primary key values to break.
  284. The new :attr:`~django.test.TransactionTestCase.reset_sequences` attribute can
  285. be used to force the old behavior for :class:`~django.test.TransactionTestCase`
  286. that might need it.
  287. Ordering of tests
  288. ^^^^^^^^^^^^^^^^^
  289. In order to make sure all ``TestCase`` code starts with a clean database,
  290. tests are now executed in the following order:
  291. * First, all unittests (including :class:`unittest.TestCase`,
  292. :class:`~django.test.SimpleTestCase`, :class:`~django.test.TestCase` and
  293. :class:`~django.test.TransactionTestCase`) are run with no particular ordering
  294. guaranteed nor enforced among them.
  295. * Then any other tests (e.g. doctests) that may alter the database without
  296. restoring it to its original state are run.
  297. This should not cause any problems unless you have existing doctests which
  298. assume a :class:`~django.test.TransactionTestCase` executed earlier left some
  299. database state behind or unit tests that rely on some form of state being
  300. preserved after the execution of other tests. Such tests are already very
  301. fragile, and must now be changed to be able to run independently.
  302. `cleaned_data` dictionary kept for invalid forms
  303. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  304. The :attr:`~django.forms.Form.cleaned_data` dictionary is now always present
  305. after form validation. When the form doesn't validate, it contains only the
  306. fields that passed validation. You should test the success of the validation
  307. with the :meth:`~django.forms.Form.is_valid()` method and not with the
  308. presence or absence of the :attr:`~django.forms.Form.cleaned_data` attribute
  309. on the form.
  310. Miscellaneous
  311. ~~~~~~~~~~~~~
  312. * :func:`~django.utils.http.int_to_base36` properly raises a :exc:`TypeError`
  313. instead of :exc:`ValueError` for non-integer inputs.
  314. * The ``slugify`` template filter is now available as a standard python
  315. function at :func:`django.utils.text.slugify`. Similarly, ``remove_tags`` is
  316. available at :func:`django.utils.html.remove_tags`.
  317. * Uploaded files are no longer created as executable by default. If you need
  318. them to be executeable change :setting:`FILE_UPLOAD_PERMISSIONS` to your
  319. needs. The new default value is `0666` (octal) and the current umask value
  320. is first masked out.
  321. Features deprecated in 1.5
  322. ==========================
  323. .. _simplejson-deprecation:
  324. ``django.utils.simplejson``
  325. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  326. Since Django 1.5 drops support for Python 2.5, we can now rely on the
  327. :mod:`json` module being available in Python's standard library, so we've
  328. removed our own copy of :mod:`simplejson`. You should now import :mod:`json`
  329. instead :mod:`django.utils.simplejson`.
  330. Unfortunately, this change might have unwanted side-effects, because of
  331. incompatibilities between versions of :mod:`simplejson` -- see the
  332. :ref:`backwards-incompatible changes <simplejson-incompatibilities>` section.
  333. If you rely on features added to :mod:`simplejson` after it became Python's
  334. :mod:`json`, you should import :mod:`simplejson` explicitly.
  335. ``itercompat.product``
  336. ~~~~~~~~~~~~~~~~~~~~~~
  337. The :func:`~django.utils.itercompat.product` function has been deprecated. Use
  338. the built-in :func:`itertools.product` instead.
  339. ``django.utils.encoding.StrAndUnicode``
  340. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  341. The :class:`~django.utils.encoding.StrAndUnicode` mix-in has been deprecated.
  342. Define a ``__str__`` method and apply the
  343. :func:`~django.utils.encoding.python_2_unicode_compatible` decorator instead.
  344. ``django.utils.markup``
  345. ~~~~~~~~~~~~~~~~~~~~~~~
  346. The markup contrib module has been deprecated and will follow an accelerated
  347. deprecation schedule. Direct use of python markup libraries or 3rd party tag
  348. libraries is preferred to Django maintaining this functionality in the
  349. framework.
  350. :setting:`AUTH_PROFILE_MODULE`
  351. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  352. With the introduction of :ref:`custom User models <auth-custom-user>`, there is
  353. no longer any need for a built-in mechanism to store user profile data.
  354. You can still define user profiles models that have a one-to-one relation with
  355. the User model - in fact, for many applications needing to associate data with
  356. a User account, this will be an appropriate design pattern to follow. However,
  357. the :setting:`AUTH_PROFILE_MODULE` setting, and the
  358. :meth:`~django.contrib.auth.models.User.get_profile()` method for accessing
  359. the user profile model, should not be used any longer.