1.5.txt 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  1. ========================
  2. Django 1.5 release notes
  3. ========================
  4. *February 26, 2013*
  5. Welcome to Django 1.5!
  6. These release notes cover the :ref:`new features <whats-new-1.5>`, as well as
  7. some :ref:`backwards incompatible changes <backwards-incompatible-1.5>` you'll
  8. want to be aware of when upgrading from Django 1.4 or older versions. We've
  9. also dropped some features, which are detailed in :ref:`our deprecation plan
  10. <deprecation-removed-in-1.5>`, and we've :ref:`begun the deprecation process
  11. for some features <deprecated-features-1.5>`.
  12. Overview
  13. ========
  14. The biggest new feature in Django 1.5 is the `configurable User model`_. Before
  15. Django 1.5, applications that wanted to use Django's auth framework
  16. (:mod:`django.contrib.auth`) were forced to use Django's definition of a "user".
  17. In Django 1.5, you can now swap out the ``User`` model for one that you write
  18. yourself. This could be a simple extension to the existing ``User`` model -- for
  19. example, you could add a Twitter or Facebook ID field -- or you could completely
  20. replace the ``User`` with one totally customized for your site.
  21. Django 1.5 is also the first release with `Python 3 support`_! We're labeling
  22. this support "experimental" because we don't yet consider it production-ready,
  23. but everything's in place for you to start porting your apps to Python 3.
  24. Our next release, Django 1.6, will support Python 3 without reservations.
  25. Other notable new features in Django 1.5 include:
  26. * `Support for saving a subset of model's fields`_ -
  27. :meth:`Model.save() <django.db.models.Model.save()>` now accepts an
  28. ``update_fields`` argument, letting you specify which fields are
  29. written back to the database when you call ``save()``. This can help
  30. in high-concurrency operations, and can improve performance.
  31. * Better `support for streaming responses <#explicit-streaming-responses>`_ via
  32. the new :class:`~django.http.StreamingHttpResponse` response class.
  33. * `GeoDjango`_ now supports PostGIS 2.0.
  34. * ... and more; `see below <#what-s-new-in-django-1-5>`_.
  35. Wherever possible we try to introduce new features in a backwards-compatible
  36. manner per :doc:`our API stability policy </misc/api-stability>`.
  37. However, as with previous releases, Django 1.5 ships with some minor
  38. :ref:`backwards incompatible changes <backwards-incompatible-1.5>`; people
  39. upgrading from previous versions of Django should read that list carefully.
  40. One deprecated feature worth noting is the shift to "new-style" :ttag:`url` tag.
  41. Prior to Django 1.3, syntax like ``{% url myview %}`` was interpreted
  42. incorrectly (Django considered ``"myview"`` to be a literal name of a view, not
  43. a template variable named ``myview``). Django 1.3 and above introduced the
  44. ``{% load url from future %}`` syntax to bring in the corrected behavior where
  45. ``myview`` was seen as a variable.
  46. The upshot of this is that if you are not using ``{% load url from future %}``
  47. in your templates, you'll need to change tags like ``{% url myview %}`` to
  48. ``{% url "myview" %}``. If you *were* using ``{% load url from future %}`` you
  49. can simply remove that line under Django 1.5
  50. Python compatibility
  51. ====================
  52. Django 1.5 requires Python 2.6.5 or above, though we **highly recommend**
  53. Python 2.7.3 or above. Support for Python 2.5 and below has been dropped.
  54. This change should affect only a small number of Django users, as most
  55. operating-system vendors today are shipping Python 2.6 or newer as their default
  56. version. If you're still using Python 2.5, however, you'll need to stick to
  57. Django 1.4 until you can upgrade your Python version. Per :doc:`our support
  58. policy </internals/release-process>`, Django 1.4 will continue to receive
  59. security support until the release of Django 1.6.
  60. Django 1.5 does not run on a Jython final release, because Jython's latest
  61. release doesn't currently support Python 2.6. However, Jython currently does
  62. offer an alpha release featuring 2.7 support, and Django 1.5 supports that alpha
  63. release.
  64. Python 3 support
  65. ----------------
  66. Django 1.5 introduces support for Python 3 - specifically, Python
  67. 3.2 and above. This comes in the form of a **single** codebase; you don't
  68. need to install a different version of Django on Python 3. This means that
  69. you can write applications targeted for just Python 2, just Python 3, or single
  70. applications that support both platforms.
  71. However, we're labeling this support "experimental" for now: although it's
  72. received extensive testing via our automated test suite, it's received very
  73. little real-world testing. We've done our best to eliminate bugs, but we can't
  74. be sure we covered all possible uses of Django.
  75. Some features of Django aren't available because they depend on third-party
  76. software that hasn't been ported to Python 3 yet, including:
  77. - the MySQL database backend (depends on MySQLdb)
  78. - :class:`~django.db.models.ImageField` (depends on PIL)
  79. - :class:`~django.test.LiveServerTestCase` (depends on Selenium WebDriver)
  80. Further, Django's more than a web framework; it's an ecosystem of pluggable
  81. components. At this point, very few third-party applications have been ported
  82. to Python 3, so it's unlikely that a real-world application will have all its
  83. dependencies satisfied under Python 3.
  84. Thus, we're recommending that Django 1.5 not be used in production under Python
  85. 3. Instead, use this opportunity to begin porting applications to Python 3. If
  86. you're an author of a pluggable component, we encourage you to start porting
  87. now.
  88. We plan to offer first-class, production-ready support for Python 3 in our next
  89. release, Django 1.6.
  90. .. _whats-new-1.5:
  91. What's new in Django 1.5
  92. ========================
  93. Configurable User model
  94. -----------------------
  95. In Django 1.5, you can now use your own model as the store for user-related
  96. data. If your project needs a username with more than 30 characters, or if
  97. you want to store user's names in a format other than first name/last name,
  98. or you want to put custom profile information onto your User object, you can
  99. now do so.
  100. If you have a third-party reusable application that references the User model,
  101. you may need to make some changes to the way you reference User instances. You
  102. should also document any specific features of the User model that your
  103. application relies upon.
  104. See the :ref:`documentation on custom user models <auth-custom-user>` for
  105. more details.
  106. Support for saving a subset of model's fields
  107. ---------------------------------------------
  108. The method :meth:`Model.save() <django.db.models.Model.save()>` has a new
  109. keyword argument ``update_fields``. By using this argument it is possible to
  110. save only a select list of model's fields. This can be useful for performance
  111. reasons or when trying to avoid overwriting concurrent changes.
  112. Deferred instances (those loaded by ``.only()`` or ``.defer()``) will
  113. automatically save just the loaded fields. If any field is set manually after
  114. load, that field will also get updated on save.
  115. See the :meth:`Model.save() <django.db.models.Model.save()>` documentation for
  116. more details.
  117. Caching of related model instances
  118. ----------------------------------
  119. When traversing relations, the ORM will avoid re-fetching objects that were
  120. previously loaded. For example, with the tutorial's models:
  121. .. code-block:: pycon
  122. >>> first_poll = Poll.objects.all()[0]
  123. >>> first_choice = first_poll.choice_set.all()[0]
  124. >>> first_choice.poll is first_poll
  125. True
  126. In Django 1.5, the third line no longer triggers a new SQL query to fetch
  127. ``first_choice.poll``; it was set by the second line.
  128. For one-to-one relationships, both sides can be cached. For many-to-one
  129. relationships, only the single side of the relationship can be cached. This
  130. is particularly helpful in combination with ``prefetch_related``.
  131. .. _explicit-streaming-responses:
  132. Explicit support for streaming responses
  133. ----------------------------------------
  134. Before Django 1.5, it was possible to create a streaming response by passing
  135. an iterator to :class:`~django.http.HttpResponse`. But this was unreliable:
  136. any middleware that accessed the :attr:`~django.http.HttpResponse.content`
  137. attribute would consume the iterator prematurely.
  138. You can now explicitly generate a streaming response with the new
  139. :class:`~django.http.StreamingHttpResponse` class. This class exposes a
  140. :class:`~django.http.StreamingHttpResponse.streaming_content` attribute which
  141. is an iterator.
  142. Since :class:`~django.http.StreamingHttpResponse` does not have a ``content``
  143. attribute, middleware that needs access to the response content must test for
  144. streaming responses and behave accordingly.
  145. ``{% verbatim %}`` template tag
  146. -------------------------------
  147. To make it easier to deal with JavaScript templates which collide with Django's
  148. syntax, you can now use the :ttag:`verbatim` block tag to avoid parsing the
  149. tag's content.
  150. Retrieval of ``ContentType`` instances associated with proxy models
  151. -------------------------------------------------------------------
  152. The methods :meth:`ContentTypeManager.get_for_model() <django.contrib.contenttypes.models.ContentTypeManager.get_for_model()>`
  153. and :meth:`ContentTypeManager.get_for_models() <django.contrib.contenttypes.models.ContentTypeManager.get_for_models()>`
  154. have a new keyword argument – respectively ``for_concrete_model`` and ``for_concrete_models``.
  155. By passing ``False`` using this argument it is now possible to retrieve the
  156. :class:`ContentType <django.contrib.contenttypes.models.ContentType>`
  157. associated with proxy models.
  158. New ``view`` variable in class-based views context
  159. --------------------------------------------------
  160. In all :doc:`generic class-based views </topics/class-based-views/index>`
  161. (or any class-based view inheriting from ``ContextMixin``), the context dictionary
  162. contains a ``view`` variable that points to the ``View`` instance.
  163. GeoDjango
  164. ---------
  165. * :class:`~django.contrib.gis.geos.LineString` and
  166. :class:`~django.contrib.gis.geos.MultiLineString` GEOS objects now support the
  167. :meth:`~django.contrib.gis.geos.GEOSGeometry.interpolate()` and
  168. :meth:`~django.contrib.gis.geos.GEOSGeometry.project()` methods
  169. (so-called linear referencing).
  170. * The ``wkb`` and ``hex`` properties of
  171. :class:`~django.contrib.gis.geos.GEOSGeometry` objects preserve the Z
  172. dimension.
  173. * Support for PostGIS 2.0 has been added and support for GDAL < 1.5 has been
  174. dropped.
  175. New tutorials
  176. -------------
  177. Additions to the docs include a revamped :doc:`Tutorial 3</intro/tutorial03>`
  178. and a new :doc:`tutorial on testing</intro/tutorial05>`. A new section,
  179. "Advanced Tutorials", offers :doc:`How to write reusable apps
  180. </intro/reusable-apps>` as well as a step-by-step guide for new contributors in
  181. :doc:`Writing your first patch for Django </intro/contributing>`.
  182. Minor features
  183. --------------
  184. Django 1.5 also includes several smaller improvements worth noting:
  185. * The template engine now interprets ``True``, ``False`` and ``None`` as the
  186. corresponding Python objects.
  187. * :mod:`django.utils.timezone` provides a helper for converting aware
  188. datetimes between time zones. See :func:`~django.utils.timezone.localtime`.
  189. * The generic views support OPTIONS requests.
  190. * Management commands do not raise ``SystemExit`` any more when called by code
  191. from :func:`~django.core.management.call_command`. Any exception raised by
  192. the command (mostly :exc:`~django.core.management.CommandError`) is
  193. propagated.
  194. Moreover, when you output errors or messages in your custom commands, you
  195. should now use ``self.stdout.write('message')`` and
  196. ``self.stderr.write('error')`` (see the note on
  197. :ref:`management commands output <management-commands-output>`).
  198. * The :djadmin:`dumpdata` management command outputs one row at a time,
  199. preventing out-of-memory errors when dumping large datasets.
  200. * In the localflavor for Canada, ``pq`` was added to the acceptable codes for
  201. Quebec. It's an old abbreviation.
  202. * The :ref:`receiver <connecting-receiver-functions>` decorator is now able to
  203. connect to more than one signal by supplying a list of signals.
  204. * In the admin, you can now filter users by groups which they are members of.
  205. * :meth:`QuerySet.bulk_create()
  206. <django.db.models.query.QuerySet.bulk_create>` now has a batch_size
  207. argument. By default the batch_size is unlimited except for SQLite where
  208. single batch is limited so that 999 parameters per query isn't exceeded.
  209. * The :setting:`LOGIN_URL` and :setting:`LOGIN_REDIRECT_URL` settings now also
  210. accept view function names and
  211. :ref:`named URL patterns <naming-url-patterns>`. This allows you to reduce
  212. configuration duplication. More information can be found in the
  213. :func:`~django.contrib.auth.decorators.login_required` documentation.
  214. * Django now provides a mod_wsgi :doc:`auth handler
  215. </howto/deployment/wsgi/apache-auth>`.
  216. * The :meth:`QuerySet.delete() <django.db.models.query.QuerySet.delete>`
  217. and :meth:`Model.delete() <django.db.models.Model.delete()>` can now take
  218. fast-path in some cases. The fast-path allows for less queries and less
  219. objects fetched into memory. See :meth:`QuerySet.delete()
  220. <django.db.models.query.QuerySet.delete>` for details.
  221. * An instance of ``ResolverMatch`` is stored on the request as
  222. ``resolver_match``.
  223. * By default, all logging messages reaching the ``django`` logger when
  224. :setting:`DEBUG` is ``True`` are sent to the console (unless you redefine the
  225. logger in your :setting:`LOGGING` setting).
  226. * When using :class:`~django.template.RequestContext`, it is now possible to
  227. look up permissions by using ``{% if 'someapp.someperm' in perms %}``
  228. in templates.
  229. * It's not required any more to have ``404.html`` and ``500.html`` templates in
  230. the root templates directory. Django will output some basic error messages for
  231. both situations when those templates are not found. It's still recommended as
  232. good practice to provide those templates in order to present pretty error
  233. pages to the user.
  234. * :mod:`django.contrib.auth` provides a new signal that is emitted
  235. whenever a user fails to login successfully. See
  236. :data:`~django.contrib.auth.signals.user_login_failed`
  237. * The new :option:`loaddata --ignorenonexistent` option ignore data for fields
  238. that no longer exist.
  239. * :meth:`~django.test.SimpleTestCase.assertXMLEqual` and
  240. :meth:`~django.test.SimpleTestCase.assertXMLNotEqual` new assertions allow
  241. you to test equality for XML content at a semantic level, without caring for
  242. syntax differences (spaces, attribute order, etc.).
  243. * RemoteUserMiddleware now forces logout when the REMOTE_USER header
  244. disappears during the same browser session.
  245. * The :ref:`cache-based session backend <cached-sessions-backend>` can store
  246. session data in a non-default cache.
  247. * Multi-column indexes can now be created on models. Read the
  248. ``index_together`` documentation for more information.
  249. * During Django's logging configuration verbose Deprecation warnings are
  250. enabled and warnings are captured into the logging system. Logged warnings
  251. are routed through the ``console`` logging handler, which by default requires
  252. :setting:`DEBUG` to be True for output to be generated. The result is that
  253. DeprecationWarnings should be printed to the console in development
  254. environments the way they have been in Python versions < 2.7.
  255. * The API for :meth:`django.contrib.admin.ModelAdmin.message_user` method has
  256. been modified to accept additional arguments adding capabilities similar to
  257. :func:`django.contrib.messages.add_message`. This is useful for generating
  258. error messages from admin actions.
  259. * The admin's list filters can now be customized per-request thanks to the new
  260. :meth:`django.contrib.admin.ModelAdmin.get_list_filter` method.
  261. .. _backwards-incompatible-1.5:
  262. Backwards incompatible changes in 1.5
  263. =====================================
  264. .. warning::
  265. In addition to the changes outlined in this section, be sure to review the
  266. :ref:`deprecation plan <deprecation-removed-in-1.5>` for any features that
  267. have been removed. If you haven't updated your code within the
  268. deprecation timeline for a given feature, its removal may appear as a
  269. backwards incompatible change.
  270. ``ALLOWED_HOSTS`` required in production
  271. ----------------------------------------
  272. The new :setting:`ALLOWED_HOSTS` setting validates the request's ``Host``
  273. header and protects against host-poisoning attacks. This setting is now
  274. required whenever :setting:`DEBUG` is ``False``, or else
  275. :meth:`django.http.HttpRequest.get_host()` will raise
  276. :exc:`~django.core.exceptions.SuspiciousOperation`. For more details see the
  277. :setting:`full documentation<ALLOWED_HOSTS>` for the new setting.
  278. Managers on abstract models
  279. ---------------------------
  280. Abstract models are able to define a custom manager, and that manager
  281. :ref:`will be inherited by any concrete models extending the abstract model
  282. <custom-managers-and-inheritance>`. However, if you try to use the abstract
  283. model to call a method on the manager, an exception will now be raised.
  284. Previously, the call would have been permitted, but would have failed as soon
  285. as any database operation was attempted (usually with a "table does not exist"
  286. error from the database).
  287. If you have functionality on a manager that you have been invoking using
  288. the abstract class, you should migrate that logic to a Python
  289. ``staticmethod`` or ``classmethod`` on the abstract class.
  290. Context in year archive class-based views
  291. -----------------------------------------
  292. For consistency with the other date-based generic views,
  293. :class:`~django.views.generic.dates.YearArchiveView` now passes ``year`` in
  294. the context as a :class:`datetime.date` rather than a string. If you are
  295. using ``{{ year }}`` in your templates, you must replace it with ``{{
  296. year|date:"Y" }}``.
  297. ``next_year`` and ``previous_year`` were also added in the context. They are
  298. calculated according to ``allow_empty`` and ``allow_future``.
  299. Context in year and month archive class-based views
  300. ---------------------------------------------------
  301. :class:`~django.views.generic.dates.YearArchiveView` and
  302. :class:`~django.views.generic.dates.MonthArchiveView` were documented to
  303. provide a ``date_list`` sorted in ascending order in the context, like their
  304. function-based predecessors, but it actually was in descending order. In 1.5,
  305. the documented order was restored. You may want to add (or remove) the
  306. ``reversed`` keyword when you're iterating on ``date_list`` in a template:
  307. .. code-block:: html+django
  308. {% for date in date_list reversed %}
  309. :class:`~django.views.generic.dates.ArchiveIndexView` still provides a
  310. ``date_list`` in descending order.
  311. Context in TemplateView
  312. -----------------------
  313. For consistency with the design of the other generic views,
  314. :class:`~django.views.generic.base.TemplateView` no longer passes a ``params``
  315. dictionary into the context, instead passing the variables from the URLconf
  316. directly into the context.
  317. Non-form data in HTTP requests
  318. ------------------------------
  319. :attr:`request.POST <django.http.HttpRequest.POST>` will no longer include data
  320. posted via HTTP requests with non form-specific content-types in the header.
  321. In prior versions, data posted with content-types other than
  322. :mimetype:`multipart/form-data` or
  323. :mimetype:`application/x-www-form-urlencoded` would still end up represented in
  324. the :attr:`request.POST <django.http.HttpRequest.POST>` attribute. Developers
  325. wishing to access the raw POST data for these cases, should use the
  326. :attr:`request.body <django.http.HttpRequest.body>` attribute instead.
  327. :data:`~django.core.signals.request_finished` signal
  328. ----------------------------------------------------
  329. Django used to send the :data:`~django.core.signals.request_finished` signal
  330. as soon as the view function returned a response. This interacted badly with
  331. :ref:`streaming responses <httpresponse-streaming>` that delay content
  332. generation.
  333. This signal is now sent after the content is fully consumed by the WSGI
  334. gateway. This might be backwards incompatible if you rely on the signal being
  335. fired before sending the response content to the client. If you do, you should
  336. consider using :doc:`middleware </topics/http/middleware>` instead.
  337. .. note::
  338. Some WSGI servers and middleware do not always call ``close`` on the
  339. response object after handling a request, most notably uWSGI prior to 1.2.6
  340. and Sentry's error reporting middleware up to 2.0.7. In those cases the
  341. ``request_finished`` signal isn't sent at all. This can result in idle
  342. connections to database and memcache servers.
  343. OPTIONS, PUT and DELETE requests in the test client
  344. ---------------------------------------------------
  345. Unlike GET and POST, these HTTP methods aren't implemented by web browsers.
  346. Rather, they're used in APIs, which transfer data in various formats such as
  347. JSON or XML. Since such requests may contain arbitrary data, Django doesn't
  348. attempt to decode their body.
  349. However, the test client used to build a query string for OPTIONS and DELETE
  350. requests like for GET, and a request body for PUT requests like for POST. This
  351. encoding was arbitrary and inconsistent with Django's behavior when it
  352. receives the requests, so it was removed in Django 1.5.
  353. If you were using the ``data`` parameter in an OPTIONS or a DELETE request,
  354. you must convert it to a query string and append it to the ``path`` parameter.
  355. If you were using the ``data`` parameter in a PUT request without a
  356. ``content_type``, you must encode your data before passing it to the test
  357. client and set the ``content_type`` argument.
  358. .. _simplejson-incompatibilities:
  359. System version of ``simplejson`` no longer used
  360. -----------------------------------------------
  361. :ref:`As explained below <simplejson-deprecation>`, Django 1.5 deprecates
  362. ``django.utils.simplejson`` in favor of Python 2.6's built-in :mod:`json`
  363. module. In theory, this change is harmless. Unfortunately, because of
  364. incompatibilities between versions of ``simplejson``, it may trigger errors
  365. in some circumstances.
  366. JSON-related features in Django 1.4 always used ``django.utils.simplejson``.
  367. This module was actually:
  368. - A system version of ``simplejson``, if one was available (i.e. ``import
  369. simplejson`` works), if it was more recent than Django's built-in copy or it
  370. had the C speedups, or
  371. - The :mod:`json` module from the standard library, if it was available (i.e.
  372. Python 2.6 or greater), or
  373. - A built-in copy of version 2.0.7 of ``simplejson``.
  374. In Django 1.5, those features use Python's :mod:`json` module, which is based
  375. on version 2.0.9 of ``simplejson``.
  376. There are no known incompatibilities between Django's copy of version 2.0.7 and
  377. Python's copy of version 2.0.9. However, there are some incompatibilities
  378. between other versions of ``simplejson``:
  379. - While the ``simplejson`` API is documented as always returning Unicode
  380. strings, the optional C implementation can return a bytestring. This was
  381. fixed in Python 2.7.
  382. - ``simplejson.JSONEncoder`` gained a ``namedtuple_as_object`` keyword
  383. argument in version 2.2.
  384. More information on these incompatibilities is available in
  385. :ticket:`ticket #18023 <18023#comment:10>`.
  386. The net result is that, if you have installed ``simplejson`` and your code
  387. uses Django's serialization internals directly -- for instance
  388. ``django.core.serializers.json.DjangoJSONEncoder``, the switch from
  389. ``simplejson`` to :mod:`json` could break your code. (In general, changes to
  390. internals aren't documented; we're making an exception here.)
  391. At this point, the maintainers of Django believe that using :mod:`json` from
  392. the standard library offers the strongest guarantee of backwards-compatibility.
  393. They recommend to use it from now on.
  394. String types of hasher method parameters
  395. ----------------------------------------
  396. If you have written a :ref:`custom password hasher <auth_password_storage>`,
  397. your ``encode()``, ``verify()`` or ``safe_summary()`` methods should accept
  398. Unicode parameters (``password``, ``salt`` or ``encoded``). If any of the
  399. hashing methods need bytestrings, you can use the
  400. :func:`~django.utils.encoding.force_bytes` utility to encode the strings.
  401. Validation of previous_page_number and next_page_number
  402. -------------------------------------------------------
  403. When using :doc:`object pagination </topics/pagination>`,
  404. the ``previous_page_number()`` and ``next_page_number()`` methods of the
  405. :class:`~django.core.paginator.Page` object did not check if the returned
  406. number was inside the existing page range.
  407. It does check it now and raises an :exc:`~django.core.paginator.InvalidPage`
  408. exception when the number is either too low or too high.
  409. Behavior of autocommit database option on PostgreSQL changed
  410. ------------------------------------------------------------
  411. PostgreSQL's autocommit option didn't work as advertised previously. It did
  412. work for single transaction block, but after the first block was left the
  413. autocommit behavior was never restored. This bug is now fixed in 1.5. While
  414. this is only a bug fix, it is worth checking your applications behavior if
  415. you are using PostgreSQL together with the autocommit option.
  416. Session not saved on 500 responses
  417. ----------------------------------
  418. Django's session middleware will skip saving the session data if the
  419. response's status code is 500.
  420. Email checks on failed admin login
  421. ----------------------------------
  422. Prior to Django 1.5, if you attempted to log into the admin interface and
  423. mistakenly used your email address instead of your username, the admin
  424. interface would provide a warning advising that your email address was
  425. not your username. In Django 1.5, the introduction of
  426. :ref:`custom user models <auth-custom-user>` has required the removal of this
  427. warning. This doesn't change the login behavior of the admin site; it only
  428. affects the warning message that is displayed under one particular mode of
  429. login failure.
  430. Changes in tests execution
  431. --------------------------
  432. Some changes have been introduced in the execution of tests that might be
  433. backward-incompatible for some testing setups:
  434. Database flushing in ``django.test.TransactionTestCase``
  435. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  436. Previously, the test database was truncated *before* each test run in a
  437. :class:`~django.test.TransactionTestCase`.
  438. In order to be able to run unit tests in any order and to make sure they are
  439. always isolated from each other, :class:`~django.test.TransactionTestCase` will
  440. now reset the database *after* each test run instead.
  441. No more implicit DB sequences reset
  442. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  443. :class:`~django.test.TransactionTestCase` tests used to reset primary key
  444. sequences automatically together with the database flushing actions described
  445. above.
  446. This has been changed so no sequences are implicitly reset. This can cause
  447. :class:`~django.test.TransactionTestCase` tests that depend on hard-coded
  448. primary key values to break.
  449. The new :attr:`~django.test.TransactionTestCase.reset_sequences` attribute can
  450. be used to force the old behavior for :class:`~django.test.TransactionTestCase`
  451. that might need it.
  452. Ordering of tests
  453. ~~~~~~~~~~~~~~~~~
  454. In order to make sure all ``TestCase`` code starts with a clean database,
  455. tests are now executed in the following order:
  456. * First, all unit tests (including :class:`unittest.TestCase`,
  457. :class:`~django.test.SimpleTestCase`, :class:`~django.test.TestCase` and
  458. :class:`~django.test.TransactionTestCase`) are run with no particular ordering
  459. guaranteed nor enforced among them.
  460. * Then any other tests (e.g. doctests) that may alter the database without
  461. restoring it to its original state are run.
  462. This should not cause any problems unless you have existing doctests which
  463. assume a :class:`~django.test.TransactionTestCase` executed earlier left some
  464. database state behind or unit tests that rely on some form of state being
  465. preserved after the execution of other tests. Such tests are already very
  466. fragile, and must now be changed to be able to run independently.
  467. ``cleaned_data`` dictionary kept for invalid forms
  468. --------------------------------------------------
  469. The :attr:`~django.forms.Form.cleaned_data` dictionary is now always present
  470. after form validation. When the form doesn't validate, it contains only the
  471. fields that passed validation. You should test the success of the validation
  472. with the :meth:`~django.forms.Form.is_valid()` method and not with the
  473. presence or absence of the :attr:`~django.forms.Form.cleaned_data` attribute
  474. on the form.
  475. Behavior of ``syncdb`` with multiple databases
  476. ----------------------------------------------
  477. ``syncdb`` now queries the database routers to determine if content
  478. types (when :mod:`~django.contrib.contenttypes` is enabled) and permissions
  479. (when :mod:`~django.contrib.auth` is enabled) should be created in the target
  480. database. Previously, it created them in the default database, even when
  481. another database was specified with the ``--database`` option.
  482. If you use ``syncdb`` on multiple databases, you should ensure that
  483. your routers allow synchronizing content types and permissions to only one of
  484. them. See the docs on the :ref:`behavior of contrib apps with multiple
  485. databases <contrib_app_multiple_databases>` for more information.
  486. XML deserializer will not parse documents with a DTD
  487. ----------------------------------------------------
  488. In order to prevent exposure to denial-of-service attacks related to external
  489. entity references and entity expansion, the XML model deserializer now refuses
  490. to parse XML documents containing a DTD (DOCTYPE definition). Since the XML
  491. serializer does not output a DTD, this will not impact typical usage, only
  492. cases where custom-created XML documents are passed to Django's model
  493. deserializer.
  494. Formsets default ``max_num``
  495. ----------------------------
  496. A (default) value of ``None`` for the ``max_num`` argument to a formset factory
  497. no longer defaults to allowing any number of forms in the formset. Instead, in
  498. order to prevent memory-exhaustion attacks, it now defaults to a limit of 1000
  499. forms. This limit can be raised by explicitly setting a higher value for
  500. ``max_num``.
  501. Miscellaneous
  502. -------------
  503. * :class:`django.forms.ModelMultipleChoiceField` now returns an empty
  504. ``QuerySet`` as the empty value instead of an empty list.
  505. * :func:`~django.utils.http.int_to_base36` properly raises a
  506. :exc:`TypeError` instead of :exc:`ValueError` for non-integer inputs.
  507. * The ``slugify`` template filter is now available as a standard Python
  508. function at :func:`django.utils.text.slugify`. Similarly, ``remove_tags`` is
  509. available at ``django.utils.html.remove_tags()``.
  510. * Uploaded files are no longer created as executable by default. If you need
  511. them to be executable change :setting:`FILE_UPLOAD_PERMISSIONS` to your
  512. needs. The new default value is ``0o666`` (octal) and the current umask value
  513. is first masked out.
  514. * The :class:`F expressions <django.db.models.F>` supported bitwise operators by
  515. ``&`` and ``|``. These operators are now available using ``.bitand()`` and
  516. ``.bitor()`` instead. The removal of ``&`` and ``|`` was done to be
  517. consistent with :ref:`Q() expressions <complex-lookups-with-q>` and
  518. ``QuerySet`` combining where the operators are used as boolean AND and OR
  519. operators.
  520. * In a ``filter()`` call, when :class:`F expressions <django.db.models.F>`
  521. contained lookups spanning multi-valued relations, they didn't always reuse
  522. the same relations as other lookups along the same chain. This was changed,
  523. and now F() expressions will always use the same relations as other lookups
  524. within the same ``filter()`` call.
  525. * The :ttag:`csrf_token` template tag is no longer enclosed in a div. If you need
  526. HTML validation against pre-HTML5 Strict DTDs, you should add a div around it
  527. in your pages.
  528. * The template tags library ``adminmedia``, which only contained the
  529. deprecated template tag ``{% admin_media_prefix %}``, was removed.
  530. Attempting to load it with ``{% load adminmedia %}`` will fail. If your
  531. templates still contain that line you must remove it.
  532. * Because of an implementation oversight, it was possible to use
  533. :doc:`django.contrib.redirects </ref/contrib/redirects>` without enabling
  534. :doc:`django.contrib.sites </ref/contrib/sites>`. This isn't allowed any
  535. longer. If you're using ``django.contrib.redirects``, make sure
  536. :setting:`INSTALLED_APPS` contains ``django.contrib.sites``.
  537. * :meth:`BoundField.label_tag <django.forms.BoundField.label_tag>` now
  538. escapes its ``contents`` argument. To avoid the HTML escaping, use
  539. :func:`django.utils.safestring.mark_safe` on the argument before passing it.
  540. * Accessing reverse one-to-one relations fetched via
  541. :meth:`~django.db.models.query.QuerySet.select_related` now raises
  542. :exc:`~django.db.models.Model.DoesNotExist` instead of returning ``None``.
  543. .. _deprecated-features-1.5:
  544. Features deprecated in 1.5
  545. ==========================
  546. ``django.contrib.localflavor``
  547. ------------------------------
  548. The localflavor contrib app has been split into separate packages.
  549. ``django.contrib.localflavor`` itself will be removed in Django 1.6,
  550. after an accelerated deprecation.
  551. The new packages are available on GitHub. The core team cannot
  552. efficiently maintain these packages in the long term — it spans just a
  553. dozen countries at this time; similar to translations, maintenance
  554. will be handed over to interested members of the community.
  555. ``django.contrib.markup``
  556. -------------------------
  557. The markup contrib module has been deprecated and will follow an accelerated
  558. deprecation schedule. Direct use of Python markup libraries or 3rd party tag
  559. libraries is preferred to Django maintaining this functionality in the
  560. framework.
  561. ``AUTH_PROFILE_MODULE``
  562. -----------------------
  563. With the introduction of :ref:`custom user models <auth-custom-user>`, there is
  564. no longer any need for a built-in mechanism to store user profile data.
  565. You can still define user profiles models that have a one-to-one relation with
  566. the User model - in fact, for many applications needing to associate data with
  567. a User account, this will be an appropriate design pattern to follow. However,
  568. the ``AUTH_PROFILE_MODULE`` setting, and the
  569. ``django.contrib.auth.models.User.get_profile()`` method for accessing
  570. the user profile model, should not be used any longer.
  571. Streaming behavior of :class:`~django.http.HttpResponse`
  572. --------------------------------------------------------
  573. Django 1.5 deprecates the ability to stream a response by passing an iterator
  574. to :class:`~django.http.HttpResponse`. If you rely on this behavior, switch to
  575. :class:`~django.http.StreamingHttpResponse`. See
  576. :ref:`explicit-streaming-responses` above.
  577. In Django 1.7 and above, the iterator will be consumed immediately by
  578. :class:`~django.http.HttpResponse`.
  579. .. _simplejson-deprecation:
  580. ``django.utils.simplejson``
  581. ---------------------------
  582. Since Django 1.5 drops support for Python 2.5, we can now rely on the
  583. :mod:`json` module being available in Python's standard library, so we've
  584. removed our own copy of ``simplejson``. You should now import :mod:`json`
  585. instead of ``django.utils.simplejson``.
  586. Unfortunately, this change might have unwanted side-effects, because of
  587. incompatibilities between versions of ``simplejson`` -- see the
  588. :ref:`backwards-incompatible changes <simplejson-incompatibilities>` section.
  589. If you rely on features added to ``simplejson`` after it became Python's
  590. :mod:`json`, you should import ``simplejson`` explicitly.
  591. ``django.utils.encoding.StrAndUnicode``
  592. ---------------------------------------
  593. The ``django.utils.encoding.StrAndUnicode`` mix-in has been deprecated.
  594. Define a ``__str__`` method and apply the
  595. ``django.utils.encoding.python_2_unicode_compatible`` decorator instead.
  596. ``django.utils.itercompat.product``
  597. -----------------------------------
  598. The ``django.utils.itercompat.product`` function has been deprecated. Use
  599. the built-in :func:`itertools.product` instead.
  600. ``cleanup`` management command
  601. ------------------------------
  602. The ``cleanup`` management command has been deprecated and replaced by
  603. :djadmin:`clearsessions`.
  604. ``daily_cleanup.py`` script
  605. ---------------------------
  606. The undocumented ``daily_cleanup.py`` script has been deprecated. Use the
  607. :djadmin:`clearsessions` management command instead.
  608. ``depth`` keyword argument in ``select_related``
  609. ------------------------------------------------
  610. The ``depth`` keyword argument in
  611. :meth:`~django.db.models.query.QuerySet.select_related` has been deprecated.
  612. You should use field names instead.