1.5.txt 36 KB

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