1.5.txt 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  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. * :mod:`django.contrib.auth` provides a new signal that is emitted
  145. whenever a user fails to login successfully. See
  146. :data:`~django.contrib.auth.signals.user_login_failed`
  147. * The loaddata management command now supports an `ignorenonexistent` option to
  148. ignore data for fields that no longer exist.
  149. Backwards incompatible changes in 1.5
  150. =====================================
  151. .. warning::
  152. In addition to the changes outlined in this section, be sure to review the
  153. :doc:`deprecation plan </internals/deprecation>` for any features that
  154. have been removed. If you haven't updated your code within the
  155. deprecation timeline for a given feature, its removal may appear as a
  156. backwards incompatible change.
  157. Context in year archive class-based views
  158. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  159. For consistency with the other date-based generic views,
  160. :class:`~django.views.generic.dates.YearArchiveView` now passes ``year`` in
  161. the context as a :class:`datetime.date` rather than a string. If you are
  162. using ``{{ year }}`` in your templates, you must replace it with ``{{
  163. year|date:"Y" }}``.
  164. ``next_year`` and ``previous_year`` were also added in the context. They are
  165. calculated according to ``allow_empty`` and ``allow_future``.
  166. Context in year and month archive class-based views
  167. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  168. :class:`~django.views.generic.dates.YearArchiveView` and
  169. :class:`~django.views.generic.dates.MonthArchiveView` were documented to
  170. provide a ``date_list`` sorted in ascending order in the context, like their
  171. function-based predecessors, but it actually was in descending order. In 1.5,
  172. the documented order was restored. You may want to add (or remove) the
  173. ``reversed`` keyword when you're iterating on ``date_list`` in a template::
  174. {% for date in date_list reversed %}
  175. :class:`~django.views.generic.dates.ArchiveIndexView` still provides a
  176. ``date_list`` in descending order.
  177. Context in TemplateView
  178. ~~~~~~~~~~~~~~~~~~~~~~~
  179. For consistency with the design of the other generic views,
  180. :class:`~django.views.generic.base.TemplateView` no longer passes a ``params``
  181. dictionary into the context, instead passing the variables from the URLconf
  182. directly into the context.
  183. OPTIONS, PUT and DELETE requests in the test client
  184. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  185. Unlike GET and POST, these HTTP methods aren't implemented by web browsers.
  186. Rather, they're used in APIs, which transfer data in various formats such as
  187. JSON or XML. Since such requests may contain arbitrary data, Django doesn't
  188. attempt to decode their body.
  189. However, the test client used to build a query string for OPTIONS and DELETE
  190. requests like for GET, and a request body for PUT requests like for POST. This
  191. encoding was arbitrary and inconsistent with Django's behavior when it
  192. receives the requests, so it was removed in Django 1.5.
  193. If you were using the ``data`` parameter in an OPTIONS or a DELETE request,
  194. you must convert it to a query string and append it to the ``path`` parameter.
  195. If you were using the ``data`` parameter in a PUT request without a
  196. ``content_type``, you must encode your data before passing it to the test
  197. client and set the ``content_type`` argument.
  198. .. _simplejson-incompatibilities:
  199. System version of :mod:`simplejson` no longer used
  200. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  201. :ref:`As explained below <simplejson-deprecation>`, Django 1.5 deprecates
  202. :mod:`django.utils.simplejson` in favor of Python 2.6's built-in :mod:`json`
  203. module. In theory, this change is harmless. Unfortunately, because of
  204. incompatibilities between versions of :mod:`simplejson`, it may trigger errors
  205. in some circumstances.
  206. JSON-related features in Django 1.4 always used :mod:`django.utils.simplejson`.
  207. This module was actually:
  208. - A system version of :mod:`simplejson`, if one was available (ie. ``import
  209. simplejson`` works), if it was more recent than Django's built-in copy or it
  210. had the C speedups, or
  211. - The :mod:`json` module from the standard library, if it was available (ie.
  212. Python 2.6 or greater), or
  213. - A built-in copy of version 2.0.7 of :mod:`simplejson`.
  214. In Django 1.5, those features use Python's :mod:`json` module, which is based
  215. on version 2.0.9 of :mod:`simplejson`.
  216. There are no known incompatibilities between Django's copy of version 2.0.7 and
  217. Python's copy of version 2.0.9. However, there are some incompatibilities
  218. between other versions of :mod:`simplejson`:
  219. - While the :mod:`simplejson` API is documented as always returning unicode
  220. strings, the optional C implementation can return a byte string. This was
  221. fixed in Python 2.7.
  222. - :class:`simplejson.JSONEncoder` gained a ``namedtuple_as_object`` keyword
  223. argument in version 2.2.
  224. More information on these incompatibilities is available in `ticket #18023`_.
  225. The net result is that, if you have installed :mod:`simplejson` and your code
  226. uses Django's serialization internals directly -- for instance
  227. :class:`django.core.serializers.json.DjangoJSONEncoder`, the switch from
  228. :mod:`simplejson` to :mod:`json` could break your code. (In general, changes to
  229. internals aren't documented; we're making an exception here.)
  230. At this point, the maintainers of Django believe that using :mod:`json` from
  231. the standard library offers the strongest guarantee of backwards-compatibility.
  232. They recommend to use it from now on.
  233. .. _ticket #18023: https://code.djangoproject.com/ticket/18023#comment:10
  234. String types of hasher method parameters
  235. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  236. If you have written a :ref:`custom password hasher <auth_password_storage>`,
  237. your ``encode()``, ``verify()`` or ``safe_summary()`` methods should accept
  238. Unicode parameters (``password``, ``salt`` or ``encoded``). If any of the
  239. hashing methods need byte strings, you can use the
  240. :func:`~django.utils.encoding.force_bytes` utility to encode the strings.
  241. Validation of previous_page_number and next_page_number
  242. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  243. When using :doc:`object pagination </topics/pagination>`,
  244. the ``previous_page_number()`` and ``next_page_number()`` methods of the
  245. :class:`~django.core.paginator.Page` object did not check if the returned
  246. number was inside the existing page range.
  247. It does check it now and raises an :exc:`InvalidPage` exception when the number
  248. is either too low or too high.
  249. Behavior of autocommit database option on PostgreSQL changed
  250. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  251. PostgreSQL's autocommit option didn't work as advertised previously. It did
  252. work for single transaction block, but after the first block was left the
  253. autocommit behavior was never restored. This bug is now fixed in 1.5. While
  254. this is only a bug fix, it is worth checking your applications behavior if
  255. you are using PostgreSQL together with the autocommit option.
  256. Session not saved on 500 responses
  257. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  258. Django's session middleware will skip saving the session data if the
  259. response's status code is 500.
  260. Email checks on failed admin login
  261. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  262. Prior to Django 1.5, if you attempted to log into the admin interface and
  263. mistakenly used your email address instead of your username, the admin
  264. interface would provide a warning advising that your email address was
  265. not your username. In Django 1.5, the introduction of
  266. :ref:`custom User models <auth-custom-user>` has required the removal of this
  267. warning. This doesn't change the login behavior of the admin site; it only
  268. affects the warning message that is displayed under one particular mode of
  269. login failure.
  270. Changes in tests execution
  271. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  272. Some changes have been introduced in the execution of tests that might be
  273. backward-incompatible for some testing setups:
  274. Database flushing in ``django.test.TransactionTestCase``
  275. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  276. Previously, the test database was truncated *before* each test run in a
  277. :class:`~django.test.TransactionTestCase`.
  278. In order to be able to run unit tests in any order and to make sure they are
  279. always isolated from each other, :class:`~django.test.TransactionTestCase` will
  280. now reset the database *after* each test run instead.
  281. No more implict DB sequences reset
  282. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  283. :class:`~django.test.TransactionTestCase` tests used to reset primary key
  284. sequences automatically together with the database flushing actions described
  285. above.
  286. This has been changed so no sequences are implicitly reset. This can cause
  287. :class:`~django.test.TransactionTestCase` tests that depend on hard-coded
  288. primary key values to break.
  289. The new :attr:`~django.test.TransactionTestCase.reset_sequences` attribute can
  290. be used to force the old behavior for :class:`~django.test.TransactionTestCase`
  291. that might need it.
  292. Ordering of tests
  293. ^^^^^^^^^^^^^^^^^
  294. In order to make sure all ``TestCase`` code starts with a clean database,
  295. tests are now executed in the following order:
  296. * First, all unittests (including :class:`unittest.TestCase`,
  297. :class:`~django.test.SimpleTestCase`, :class:`~django.test.TestCase` and
  298. :class:`~django.test.TransactionTestCase`) are run with no particular ordering
  299. guaranteed nor enforced among them.
  300. * Then any other tests (e.g. doctests) that may alter the database without
  301. restoring it to its original state are run.
  302. This should not cause any problems unless you have existing doctests which
  303. assume a :class:`~django.test.TransactionTestCase` executed earlier left some
  304. database state behind or unit tests that rely on some form of state being
  305. preserved after the execution of other tests. Such tests are already very
  306. fragile, and must now be changed to be able to run independently.
  307. `cleaned_data` dictionary kept for invalid forms
  308. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  309. The :attr:`~django.forms.Form.cleaned_data` dictionary is now always present
  310. after form validation. When the form doesn't validate, it contains only the
  311. fields that passed validation. You should test the success of the validation
  312. with the :meth:`~django.forms.Form.is_valid()` method and not with the
  313. presence or absence of the :attr:`~django.forms.Form.cleaned_data` attribute
  314. on the form.
  315. Miscellaneous
  316. ~~~~~~~~~~~~~
  317. * :func:`~django.utils.http.int_to_base36` properly raises a :exc:`TypeError`
  318. instead of :exc:`ValueError` for non-integer inputs.
  319. * The ``slugify`` template filter is now available as a standard python
  320. function at :func:`django.utils.text.slugify`. Similarly, ``remove_tags`` is
  321. available at :func:`django.utils.html.remove_tags`.
  322. * Uploaded files are no longer created as executable by default. If you need
  323. them to be executeable change :setting:`FILE_UPLOAD_PERMISSIONS` to your
  324. needs. The new default value is `0666` (octal) and the current umask value
  325. is first masked out.
  326. Features deprecated in 1.5
  327. ==========================
  328. .. _simplejson-deprecation:
  329. ``django.utils.simplejson``
  330. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  331. Since Django 1.5 drops support for Python 2.5, we can now rely on the
  332. :mod:`json` module being available in Python's standard library, so we've
  333. removed our own copy of :mod:`simplejson`. You should now import :mod:`json`
  334. instead :mod:`django.utils.simplejson`.
  335. Unfortunately, this change might have unwanted side-effects, because of
  336. incompatibilities between versions of :mod:`simplejson` -- see the
  337. :ref:`backwards-incompatible changes <simplejson-incompatibilities>` section.
  338. If you rely on features added to :mod:`simplejson` after it became Python's
  339. :mod:`json`, you should import :mod:`simplejson` explicitly.
  340. ``itercompat.product``
  341. ~~~~~~~~~~~~~~~~~~~~~~
  342. The :func:`~django.utils.itercompat.product` function has been deprecated. Use
  343. the built-in :func:`itertools.product` instead.
  344. ``django.utils.encoding.StrAndUnicode``
  345. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  346. The :class:`~django.utils.encoding.StrAndUnicode` mix-in has been deprecated.
  347. Define a ``__str__`` method and apply the
  348. :func:`~django.utils.encoding.python_2_unicode_compatible` decorator instead.
  349. ``django.utils.markup``
  350. ~~~~~~~~~~~~~~~~~~~~~~~
  351. The markup contrib module has been deprecated and will follow an accelerated
  352. deprecation schedule. Direct use of python markup libraries or 3rd party tag
  353. libraries is preferred to Django maintaining this functionality in the
  354. framework.
  355. :setting:`AUTH_PROFILE_MODULE`
  356. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  357. With the introduction of :ref:`custom User models <auth-custom-user>`, there is
  358. no longer any need for a built-in mechanism to store user profile data.
  359. You can still define user profiles models that have a one-to-one relation with
  360. the User model - in fact, for many applications needing to associate data with
  361. a User account, this will be an appropriate design pattern to follow. However,
  362. the :setting:`AUTH_PROFILE_MODULE` setting, and the
  363. :meth:`~django.contrib.auth.models.User.get_profile()` method for accessing
  364. the user profile model, should not be used any longer.