1.5.txt 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  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. Minor features
  85. ~~~~~~~~~~~~~~
  86. Django 1.5 also includes several smaller improvements worth noting:
  87. * The template engine now interprets ``True``, ``False`` and ``None`` as the
  88. corresponding Python objects.
  89. * :mod:`django.utils.timezone` provides a helper for converting aware
  90. datetimes between time zones. See :func:`~django.utils.timezone.localtime`.
  91. * The generic views support OPTIONS requests.
  92. * Management commands do not raise ``SystemExit`` any more when called by code
  93. from :ref:`call_command <call-command>`. Any exception raised by the command
  94. (mostly :ref:`CommandError <ref-command-exceptions>`) is propagated.
  95. * The dumpdata management command outputs one row at a time, preventing
  96. out-of-memory errors when dumping large datasets.
  97. * In the localflavor for Canada, "pq" was added to the acceptable codes for
  98. Quebec. It's an old abbreviation.
  99. * The :ref:`receiver <connecting-receiver-functions>` decorator is now able to
  100. connect to more than one signal by supplying a list of signals.
  101. * In the admin, you can now filter users by groups which they are members of.
  102. * :meth:`QuerySet.bulk_create()
  103. <django.db.models.query.QuerySet.bulk_create>` now has a batch_size
  104. argument. By default the batch_size is unlimited except for SQLite where
  105. single batch is limited so that 999 parameters per query isn't exceeded.
  106. * The :setting:`LOGIN_URL` and :setting:`LOGIN_REDIRECT_URL` settings now also
  107. accept view function names and
  108. :ref:`named URL patterns <naming-url-patterns>`. This allows you to reduce
  109. configuration duplication. More information can be found in the
  110. :func:`~django.contrib.auth.decorators.login_required` documentation.
  111. * Django now provides a mod_wsgi :doc:`auth handler
  112. </howto/deployment/wsgi/apache-auth>`
  113. Backwards incompatible changes in 1.5
  114. =====================================
  115. .. warning::
  116. In addition to the changes outlined in this section, be sure to review the
  117. :doc:`deprecation plan </internals/deprecation>` for any features that
  118. have been removed. If you haven't updated your code within the
  119. deprecation timeline for a given feature, its removal may appear as a
  120. backwards incompatible change.
  121. Context in year archive class-based views
  122. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  123. For consistency with the other date-based generic views,
  124. :class:`~django.views.generic.dates.YearArchiveView` now passes ``year`` in
  125. the context as a :class:`datetime.date` rather than a string. If you are
  126. using ``{{ year }}`` in your templates, you must replace it with ``{{
  127. year|date:"Y" }}``.
  128. ``next_year`` and ``previous_year`` were also added in the context. They are
  129. calculated according to ``allow_empty`` and ``allow_future``.
  130. Context in year and month archive class-based views
  131. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  132. :class:`~django.views.generic.dates.YearArchiveView` and
  133. :class:`~django.views.generic.dates.MonthArchiveView` were documented to
  134. provide a ``date_list`` sorted in ascending order in the context, like their
  135. function-based predecessors, but it actually was in descending order. In 1.5,
  136. the documented order was restored. You may want to add (or remove) the
  137. ``reversed`` keyword when you're iterating on ``date_list`` in a template::
  138. {% for date in date_list reversed %}
  139. :class:`~django.views.generic.dates.ArchiveIndexView` still provides a
  140. ``date_list`` in descending order.
  141. Context in TemplateView
  142. ~~~~~~~~~~~~~~~~~~~~~~~
  143. For consistency with the design of the other generic views,
  144. :class:`~django.views.generic.base.TemplateView` no longer passes a ``params``
  145. dictionary into the context, instead passing the variables from the URLconf
  146. directly into the context.
  147. OPTIONS, PUT and DELETE requests in the test client
  148. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  149. Unlike GET and POST, these HTTP methods aren't implemented by web browsers.
  150. Rather, they're used in APIs, which transfer data in various formats such as
  151. JSON or XML. Since such requests may contain arbitrary data, Django doesn't
  152. attempt to decode their body.
  153. However, the test client used to build a query string for OPTIONS and DELETE
  154. requests like for GET, and a request body for PUT requests like for POST. This
  155. encoding was arbitrary and inconsistent with Django's behavior when it
  156. receives the requests, so it was removed in Django 1.5.
  157. If you were using the ``data`` parameter in an OPTIONS or a DELETE request,
  158. you must convert it to a query string and append it to the ``path`` parameter.
  159. If you were using the ``data`` parameter in a PUT request without a
  160. ``content_type``, you must encode your data before passing it to the test
  161. client and set the ``content_type`` argument.
  162. .. _simplejson-incompatibilities:
  163. System version of :mod:`simplejson` no longer used
  164. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  165. :ref:`As explained below <simplejson-deprecation>`, Django 1.5 deprecates
  166. :mod:`django.utils.simplejson` in favor of Python 2.6's built-in :mod:`json`
  167. module. In theory, this change is harmless. Unfortunately, because of
  168. incompatibilities between versions of :mod:`simplejson`, it may trigger errors
  169. in some circumstances.
  170. JSON-related features in Django 1.4 always used :mod:`django.utils.simplejson`.
  171. This module was actually:
  172. - A system version of :mod:`simplejson`, if one was available (ie. ``import
  173. simplejson`` works), if it was more recent than Django's built-in copy or it
  174. had the C speedups, or
  175. - The :mod:`json` module from the standard library, if it was available (ie.
  176. Python 2.6 or greater), or
  177. - A built-in copy of version 2.0.7 of :mod:`simplejson`.
  178. In Django 1.5, those features use Python's :mod:`json` module, which is based
  179. on version 2.0.9 of :mod:`simplejson`.
  180. There are no known incompatibilities between Django's copy of version 2.0.7 and
  181. Python's copy of version 2.0.9. However, there are some incompatibilities
  182. between other versions of :mod:`simplejson`:
  183. - While the :mod:`simplejson` API is documented as always returning unicode
  184. strings, the optional C implementation can return a byte string. This was
  185. fixed in Python 2.7.
  186. - :class:`simplejson.JSONEncoder` gained a ``namedtuple_as_object`` keyword
  187. argument in version 2.2.
  188. More information on these incompatibilities is available in `ticket #18023`_.
  189. The net result is that, if you have installed :mod:`simplejson` and your code
  190. uses Django's serialization internals directly -- for instance
  191. :class:`django.core.serializers.json.DjangoJSONEncoder`, the switch from
  192. :mod:`simplejson` to :mod:`json` could break your code. (In general, changes to
  193. internals aren't documented; we're making an exception here.)
  194. At this point, the maintainers of Django believe that using :mod:`json` from
  195. the standard library offers the strongest guarantee of backwards-compatibility.
  196. They recommend to use it from now on.
  197. .. _ticket #18023: https://code.djangoproject.com/ticket/18023#comment:10
  198. String types of hasher method parameters
  199. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  200. If you have written a :ref:`custom password hasher <auth_password_storage>`,
  201. your ``encode()``, ``verify()`` or ``safe_summary()`` methods should accept
  202. Unicode parameters (``password``, ``salt`` or ``encoded``). If any of the
  203. hashing methods need byte strings, you can use the
  204. :func:`~django.utils.encoding.force_bytes` utility to encode the strings.
  205. Validation of previous_page_number and next_page_number
  206. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  207. When using :doc:`object pagination </topics/pagination>`,
  208. the ``previous_page_number()`` and ``next_page_number()`` methods of the
  209. :class:`~django.core.paginator.Page` object did not check if the returned
  210. number was inside the existing page range.
  211. It does check it now and raises an :exc:`InvalidPage` exception when the number
  212. is either too low or too high.
  213. Behavior of autocommit database option on PostgreSQL changed
  214. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  215. PostgreSQL's autocommit option didn't work as advertised previously. It did
  216. work for single transaction block, but after the first block was left the
  217. autocommit behavior was never restored. This bug is now fixed in 1.5. While
  218. this is only a bug fix, it is worth checking your applications behavior if
  219. you are using PostgreSQL together with the autocommit option.
  220. Session not saved on 500 responses
  221. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  222. Django's session middleware will skip saving the session data if the
  223. response's status code is 500.
  224. Email checks on failed admin login
  225. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  226. Prior to Django 1.5, if you attempted to log into the admin interface and
  227. mistakenly used your email address instead of your username, the admin
  228. interface would provide a warning advising that your email address was
  229. not your username. In Django 1.5, the introduction of
  230. :ref:`custom User models <auth-custom-user>` has required the removal of this
  231. warning. This doesn't change the login behavior of the admin site; it only
  232. affects the warning message that is displayed under one particular mode of
  233. login failure.
  234. Changes in tests execution
  235. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  236. Some changes have been introduced in the execution of tests that might be
  237. backward-incompatible for some testing setups:
  238. Database flushing in ``django.test.TransactionTestCase``
  239. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  240. Previously, the test database was truncated *before* each test run in a
  241. :class:`~django.test.TransactionTestCase`.
  242. In order to be able to run unit tests in any order and to make sure they are
  243. always isolated from each other, :class:`~django.test.TransactionTestCase` will
  244. now reset the database *after* each test run instead.
  245. No more implict DB sequences reset
  246. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  247. :class:`~django.test.TransactionTestCase` tests used to reset primary key
  248. sequences automatically together with the database flushing actions described
  249. above.
  250. This has been changed so no sequences are implicitly reset. This can cause
  251. :class:`~django.test.TransactionTestCase` tests that depend on hard-coded
  252. primary key values to break.
  253. The new :attr:`~django.test.TransactionTestCase.reset_sequences` attribute can
  254. be used to force the old behavior for :class:`~django.test.TransactionTestCase`
  255. that might need it.
  256. Ordering of tests
  257. ^^^^^^^^^^^^^^^^^
  258. In order to make sure all ``TestCase`` code starts with a clean database,
  259. tests are now executed in the following order:
  260. * First, all unittests (including :class:`unittest.TestCase`,
  261. :class:`~django.test.SimpleTestCase`, :class:`~django.test.TestCase` and
  262. :class:`~django.test.TransactionTestCase`) are run with no particular ordering
  263. guaranteed nor enforced among them.
  264. * Then any other tests (e.g. doctests) that may alter the database without
  265. restoring it to its original state are run.
  266. This should not cause any problems unless you have existing doctests which
  267. assume a :class:`~django.test.TransactionTestCase` executed earlier left some
  268. database state behind or unit tests that rely on some form of state being
  269. preserved after the execution of other tests. Such tests are already very
  270. fragile, and must now be changed to be able to run independently.
  271. `cleaned_data` dictionary kept for invalid forms
  272. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  273. The :attr:`~django.forms.Form.cleaned_data` dictionary is now always present
  274. after form validation. When the form doesn't validate, it contains only the
  275. fields that passed validation. You should test the success of the validation
  276. with the :meth:`~django.forms.Form.is_valid()` method and not with the
  277. presence or absence of the :attr:`~django.forms.Form.cleaned_data` attribute
  278. on the form.
  279. Miscellaneous
  280. ~~~~~~~~~~~~~
  281. * GeoDjango dropped support for GDAL < 1.5
  282. * :func:`~django.utils.http.int_to_base36` properly raises a :exc:`TypeError`
  283. instead of :exc:`ValueError` for non-integer inputs.
  284. * The ``slugify`` template filter is now available as a standard python
  285. function at :func:`django.utils.text.slugify`. Similarly, ``remove_tags`` is
  286. available at :func:`django.utils.html.remove_tags`.
  287. * Uploaded files are no longer created as executable by default. If you need
  288. them to be executeable change :setting:`FILE_UPLOAD_PERMISSIONS` to your
  289. needs. The new default value is `0666` (octal) and the current umask value
  290. is first masked out.
  291. Features deprecated in 1.5
  292. ==========================
  293. .. _simplejson-deprecation:
  294. ``django.utils.simplejson``
  295. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  296. Since Django 1.5 drops support for Python 2.5, we can now rely on the
  297. :mod:`json` module being available in Python's standard library, so we've
  298. removed our own copy of :mod:`simplejson`. You should now import :mod:`json`
  299. instead :mod:`django.utils.simplejson`.
  300. Unfortunately, this change might have unwanted side-effects, because of
  301. incompatibilities between versions of :mod:`simplejson` -- see the
  302. :ref:`backwards-incompatible changes <simplejson-incompatibilities>` section.
  303. If you rely on features added to :mod:`simplejson` after it became Python's
  304. :mod:`json`, you should import :mod:`simplejson` explicitly.
  305. ``itercompat.product``
  306. ~~~~~~~~~~~~~~~~~~~~~~
  307. The :func:`~django.utils.itercompat.product` function has been deprecated. Use
  308. the built-in :func:`itertools.product` instead.
  309. ``django.utils.encoding.StrAndUnicode``
  310. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  311. The :class:`~django.utils.encoding.StrAndUnicode` mix-in has been deprecated.
  312. Define a ``__str__`` method and apply the
  313. :func:`~django.utils.encoding.python_2_unicode_compatible` decorator instead.
  314. ``django.utils.markup``
  315. ~~~~~~~~~~~~~~~~~~~~~~~
  316. The markup contrib module has been deprecated and will follow an accelerated
  317. deprecation schedule. Direct use of python markup libraries or 3rd party tag
  318. libraries is preferred to Django maintaining this functionality in the
  319. framework.
  320. :setting:`AUTH_PROFILE_MODULE`
  321. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  322. With the introduction of :ref:`custom User models <auth-custom-user>`, there is
  323. no longer any need for a built-in mechanism to store user profile data.
  324. You can still define user profiles models that have a one-to-one relation with
  325. the User model - in fact, for many applications needing to associate data with
  326. a User account, this will be an appropriate design pattern to follow. However,
  327. the :setting:`AUTH_PROFILE_MODULE` setting, and the
  328. :meth:`~django.contrib.auth.models.User.get_profile()` method for accessing
  329. the user profile model, should not be used any longer.