2012-03-30 17:33:51 +08:00
|
|
|
|
============================================
|
|
|
|
|
Django 1.5 release notes - UNDER DEVELOPMENT
|
|
|
|
|
============================================
|
|
|
|
|
|
|
|
|
|
These release notes cover the `new features`_, as well
|
|
|
|
|
as some `backwards incompatible changes`_ you'll want to be aware of
|
|
|
|
|
when upgrading from Django 1.4 or older versions. We've also dropped some
|
|
|
|
|
features, which are detailed in :doc:`our deprecation plan
|
|
|
|
|
</internals/deprecation>`, and we've `begun the deprecation process for some
|
|
|
|
|
features`_.
|
|
|
|
|
|
|
|
|
|
.. _`new features`: `What's new in Django 1.5`_
|
|
|
|
|
.. _`backwards incompatible changes`: `Backwards incompatible changes in 1.5`_
|
|
|
|
|
.. _`begun the deprecation process for some features`: `Features deprecated in 1.5`_
|
|
|
|
|
|
|
|
|
|
Python compatibility
|
|
|
|
|
====================
|
|
|
|
|
|
2012-07-13 23:30:45 +08:00
|
|
|
|
Django 1.5 has dropped support for Python 2.5. Python 2.6.5 is now the minimum
|
2012-03-30 17:33:51 +08:00
|
|
|
|
required Python version. Django is tested and supported on Python 2.6 and
|
|
|
|
|
2.7.
|
|
|
|
|
|
|
|
|
|
This change should affect only a small number of Django users, as most
|
|
|
|
|
operating-system vendors today are shipping Python 2.6 or newer as their default
|
|
|
|
|
version. If you're still using Python 2.5, however, you'll need to stick to
|
2012-04-30 02:33:54 +08:00
|
|
|
|
Django 1.4 until you can upgrade your Python version. Per :doc:`our support policy
|
2012-03-30 17:33:51 +08:00
|
|
|
|
</internals/release-process>`, Django 1.4 will continue to receive security
|
|
|
|
|
support until the release of Django 1.6.
|
|
|
|
|
|
2012-06-23 10:00:40 +08:00
|
|
|
|
Django 1.5 does not run on a Jython final release, because Jython's latest release
|
|
|
|
|
doesn't currently support Python 2.6. However, Jython currently does offer an alpha
|
|
|
|
|
release featuring 2.7 support.
|
2012-03-30 17:33:51 +08:00
|
|
|
|
|
|
|
|
|
What's new in Django 1.5
|
|
|
|
|
========================
|
|
|
|
|
|
2012-05-12 15:24:20 +08:00
|
|
|
|
Support for saving a subset of model's fields
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
The method :meth:`Model.save() <django.db.models.Model.save()>` has a new
|
|
|
|
|
keyword argument ``update_fields``. By using this argument it is possible to
|
|
|
|
|
save only a select list of model's fields. This can be useful for performance
|
|
|
|
|
reasons or when trying to avoid overwriting concurrent changes.
|
|
|
|
|
|
2012-08-13 03:17:54 +08:00
|
|
|
|
Deferred instances (those loaded by .only() or .defer()) will automatically
|
|
|
|
|
save just the loaded fields. If any field is set manually after load, that
|
|
|
|
|
field will also get updated on save.
|
|
|
|
|
|
2012-05-12 15:24:20 +08:00
|
|
|
|
See the :meth:`Model.save() <django.db.models.Model.save()>` documentation for
|
|
|
|
|
more details.
|
|
|
|
|
|
2012-05-24 19:25:01 +08:00
|
|
|
|
Caching of related model instances
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
When traversing relations, the ORM will avoid re-fetching objects that were
|
|
|
|
|
previously loaded. For example, with the tutorial's models::
|
|
|
|
|
|
|
|
|
|
>>> first_poll = Poll.objects.all()[0]
|
|
|
|
|
>>> first_choice = first_poll.choice_set.all()[0]
|
|
|
|
|
>>> first_choice.poll is first_poll
|
|
|
|
|
True
|
|
|
|
|
|
|
|
|
|
In Django 1.5, the third line no longer triggers a new SQL query to fetch
|
2012-05-26 01:03:15 +08:00
|
|
|
|
``first_choice.poll``; it was set by the second line.
|
2012-05-24 19:25:01 +08:00
|
|
|
|
|
|
|
|
|
For one-to-one relationships, both sides can be cached. For many-to-one
|
|
|
|
|
relationships, only the single side of the relationship can be cached. This
|
|
|
|
|
is particularly helpful in combination with ``prefetch_related``.
|
|
|
|
|
|
2012-06-07 15:59:14 +08:00
|
|
|
|
``{% verbatim %}`` template tag
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
To make it easier to deal with javascript templates which collide with Django's
|
|
|
|
|
syntax, you can now use the :ttag:`verbatim` block tag to avoid parsing the
|
|
|
|
|
tag's content.
|
|
|
|
|
|
2012-07-05 05:34:55 +08:00
|
|
|
|
Retrieval of ``ContentType`` instances associated with proxy models
|
2012-05-30 05:55:20 +08:00
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
2012-06-09 04:52:43 +08:00
|
|
|
|
The methods :meth:`ContentTypeManager.get_for_model() <django.contrib.contenttypes.models.ContentTypeManager.get_for_model()>`
|
|
|
|
|
and :meth:`ContentTypeManager.get_for_models() <django.contrib.contenttypes.models.ContentTypeManager.get_for_models()>`
|
|
|
|
|
have a new keyword argument – respectively ``for_concrete_model`` and ``for_concrete_models``.
|
2012-05-30 05:55:20 +08:00
|
|
|
|
By passing ``False`` using this argument it is now possible to retreive the
|
2012-06-09 04:52:43 +08:00
|
|
|
|
:class:`ContentType <django.contrib.contenttypes.models.ContentType>`
|
2012-05-30 05:55:20 +08:00
|
|
|
|
associated with proxy models.
|
|
|
|
|
|
2012-08-18 21:46:17 +08:00
|
|
|
|
New ``view`` variable in class-based views context
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
In all :doc:`generic class-based views </topics/class-based-views/index>`
|
|
|
|
|
(or any class-based view inheriting from ``ContextMixin``), the context dictionary
|
|
|
|
|
contains a ``view`` variable that points to the ``View`` instance.
|
|
|
|
|
|
2012-04-11 04:49:45 +08:00
|
|
|
|
Minor features
|
|
|
|
|
~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
Django 1.5 also includes several smaller improvements worth noting:
|
|
|
|
|
|
|
|
|
|
* The template engine now interprets ``True``, ``False`` and ``None`` as the
|
|
|
|
|
corresponding Python objects.
|
|
|
|
|
|
2012-04-29 21:37:23 +08:00
|
|
|
|
* :mod:`django.utils.timezone` provides a helper for converting aware
|
2012-04-30 02:33:54 +08:00
|
|
|
|
datetimes between time zones. See :func:`~django.utils.timezone.localtime`.
|
2012-04-29 21:37:23 +08:00
|
|
|
|
|
2012-05-17 20:03:19 +08:00
|
|
|
|
* The generic views support OPTIONS requests.
|
|
|
|
|
|
2012-05-27 02:50:44 +08:00
|
|
|
|
* Management commands do not raise ``SystemExit`` any more when called by code
|
|
|
|
|
from :ref:`call_command <call-command>`. Any exception raised by the command
|
|
|
|
|
(mostly :ref:`CommandError <ref-command-exceptions>`) is propagated.
|
|
|
|
|
|
2012-05-26 22:15:45 +08:00
|
|
|
|
* The dumpdata management command outputs one row at a time, preventing
|
|
|
|
|
out-of-memory errors when dumping large datasets.
|
|
|
|
|
|
2012-05-11 04:19:01 +08:00
|
|
|
|
* In the localflavor for Canada, "pq" was added to the acceptable codes for
|
|
|
|
|
Quebec. It's an old abbreviation.
|
|
|
|
|
|
2012-06-08 18:00:51 +08:00
|
|
|
|
* The :ref:`receiver <connecting-receiver-functions>` decorator is now able to
|
|
|
|
|
connect to more than one signal by supplying a list of signals.
|
|
|
|
|
|
2012-04-29 09:22:05 +08:00
|
|
|
|
* :meth:`QuerySet.bulk_create()
|
2012-08-07 05:28:58 +08:00
|
|
|
|
<django.db.models.query.QuerySet.bulk_create>` now has a batch_size
|
2012-04-29 09:22:05 +08:00
|
|
|
|
argument. By default the batch_size is unlimited except for SQLite where
|
|
|
|
|
single batch is limited so that 999 parameters per query isn't exceeded.
|
|
|
|
|
|
2012-03-30 17:33:51 +08:00
|
|
|
|
Backwards incompatible changes in 1.5
|
|
|
|
|
=====================================
|
|
|
|
|
|
2012-04-14 14:40:20 +08:00
|
|
|
|
.. warning::
|
|
|
|
|
|
|
|
|
|
In addition to the changes outlined in this section, be sure to review the
|
|
|
|
|
:doc:`deprecation plan </internals/deprecation>` for any features that
|
2012-04-30 02:33:54 +08:00
|
|
|
|
have been removed. If you haven't updated your code within the
|
2012-04-14 14:40:20 +08:00
|
|
|
|
deprecation timeline for a given feature, its removal may appear as a
|
|
|
|
|
backwards incompatible change.
|
|
|
|
|
|
2012-05-24 19:02:19 +08:00
|
|
|
|
Context in year archive class-based views
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
For consistency with the other date-based generic views,
|
|
|
|
|
:class:`~django.views.generic.dates.YearArchiveView` now passes ``year`` in
|
|
|
|
|
the context as a :class:`datetime.date` rather than a string. If you are
|
|
|
|
|
using ``{{ year }}`` in your templates, you must replace it with ``{{
|
|
|
|
|
year|date:"Y" }}``.
|
|
|
|
|
|
|
|
|
|
``next_year`` and ``previous_year`` were also added in the context. They are
|
|
|
|
|
calculated according to ``allow_empty`` and ``allow_future``.
|
|
|
|
|
|
2012-05-26 01:03:15 +08:00
|
|
|
|
OPTIONS, PUT and DELETE requests in the test client
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
Unlike GET and POST, these HTTP methods aren't implemented by web browsers.
|
|
|
|
|
Rather, they're used in APIs, which transfer data in various formats such as
|
|
|
|
|
JSON or XML. Since such requests may contain arbitrary data, Django doesn't
|
|
|
|
|
attempt to decode their body.
|
|
|
|
|
|
|
|
|
|
However, the test client used to build a query string for OPTIONS and DELETE
|
|
|
|
|
requests like for GET, and a request body for PUT requests like for POST. This
|
|
|
|
|
encoding was arbitrary and inconsistent with Django's behavior when it
|
|
|
|
|
receives the requests, so it was removed in Django 1.5.
|
|
|
|
|
|
|
|
|
|
If you were using the ``data`` parameter in an OPTIONS or a DELETE request,
|
|
|
|
|
you must convert it to a query string and append it to the ``path`` parameter.
|
|
|
|
|
|
|
|
|
|
If you were using the ``data`` parameter in a PUT request without a
|
|
|
|
|
``content_type``, you must encode your data before passing it to the test
|
|
|
|
|
client and set the ``content_type`` argument.
|
|
|
|
|
|
2012-06-06 16:53:16 +08:00
|
|
|
|
String types of hasher method parameters
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
If you have written a :ref:`custom password hasher <auth_password_storage>`,
|
|
|
|
|
your ``encode()``, ``verify()`` or ``safe_summary()`` methods should accept
|
|
|
|
|
Unicode parameters (``password``, ``salt`` or ``encoded``). If any of the
|
|
|
|
|
hashing methods need byte strings, you can use the
|
2012-07-21 16:00:10 +08:00
|
|
|
|
:func:`~django.utils.encoding.smart_bytes` utility to encode the strings.
|
2012-06-06 16:53:16 +08:00
|
|
|
|
|
2012-06-09 23:55:24 +08:00
|
|
|
|
Validation of previous_page_number and next_page_number
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
When using :doc:`object pagination </topics/pagination>`,
|
|
|
|
|
the ``previous_page_number()`` and ``next_page_number()`` methods of the
|
|
|
|
|
:class:`~django.core.paginator.Page` object did not check if the returned
|
|
|
|
|
number was inside the existing page range.
|
|
|
|
|
It does check it now and raises an :exc:`InvalidPage` exception when the number
|
|
|
|
|
is either too low or too high.
|
|
|
|
|
|
2012-05-27 04:19:13 +08:00
|
|
|
|
Behavior of autocommit database option on PostgreSQL changed
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
PostgreSQL's autocommit option didn't work as advertised previously. It did
|
|
|
|
|
work for single transaction block, but after the first block was left the
|
|
|
|
|
autocommit behavior was never restored. This bug is now fixed in 1.5. While
|
|
|
|
|
this is only a bug fix, it is worth checking your applications behavior if
|
|
|
|
|
you are using PostgreSQL together with the autocommit option.
|
|
|
|
|
|
2012-07-05 23:09:48 +08:00
|
|
|
|
Session not saved on 500 responses
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
Django's session middleware will skip saving the session data if the
|
|
|
|
|
response's status code is 500.
|
|
|
|
|
|
2012-07-25 04:24:16 +08:00
|
|
|
|
Changes in tests execution
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
Some changes have been introduced in the execution of tests that might be
|
|
|
|
|
backward-incompatible for some testing setups:
|
|
|
|
|
|
|
|
|
|
Database flushing in ``django.test.TransactionTestCase``
|
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
|
|
Previously, the test database was truncated *before* each test run in a
|
|
|
|
|
:class:`~django.test.TransactionTestCase`.
|
|
|
|
|
|
|
|
|
|
In order to be able to run unit tests in any order and to make sure they are
|
|
|
|
|
always isolated from each other, :class:`~django.test.TransactionTestCase` will
|
|
|
|
|
now reset the database *after* each test run instead.
|
|
|
|
|
|
|
|
|
|
No more implict DB sequences reset
|
|
|
|
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
|
|
:class:`~django.test.TransactionTestCase` tests used to reset primary key
|
|
|
|
|
sequences automatically together with the database flushing actions described
|
|
|
|
|
above.
|
|
|
|
|
|
|
|
|
|
This has been changed so no sequences are implicitly reset. This can cause
|
|
|
|
|
:class:`~django.test.TransactionTestCase` tests that depend on hard-coded
|
|
|
|
|
primary key values to break.
|
|
|
|
|
|
|
|
|
|
The new :attr:`~django.test.TransactionTestCase.reset_sequences` attribute can
|
|
|
|
|
be used to force the old behavior for :class:`~django.test.TransactionTestCase`
|
|
|
|
|
that might need it.
|
|
|
|
|
|
|
|
|
|
Ordering of tests
|
|
|
|
|
^^^^^^^^^^^^^^^^^
|
|
|
|
|
|
|
|
|
|
In order to make sure all ``TestCase`` code starts with a clean database,
|
|
|
|
|
tests are now executed in the following order:
|
|
|
|
|
|
|
|
|
|
* First, all unittests (including :class:`unittest.TestCase`,
|
|
|
|
|
:class:`~django.test.SimpleTestCase`, :class:`~django.test.TestCase` and
|
|
|
|
|
:class:`~django.test.TransactionTestCase`) are run with no particular ordering
|
|
|
|
|
guaranteed nor enforced among them.
|
|
|
|
|
|
|
|
|
|
* Then any other tests (e.g. doctests) that may alter the database without
|
|
|
|
|
restoring it to its original state are run.
|
|
|
|
|
|
|
|
|
|
This should not cause any problems unless you have existing doctests which
|
|
|
|
|
assume a :class:`~django.test.TransactionTestCase` executed earlier left some
|
|
|
|
|
database state behind or unit tests that rely on some form of state being
|
|
|
|
|
preserved after the execution of other tests. Such tests are already very
|
|
|
|
|
fragile, and must now be changed to be able to run independently.
|
|
|
|
|
|
2012-08-04 20:17:02 +08:00
|
|
|
|
`cleaned_data` dictionary kept for invalid forms
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
The :attr:`~django.forms.Form.cleaned_data` dictionary is now always present
|
|
|
|
|
after form validation. When the form doesn't validate, it contains only the
|
|
|
|
|
fields that passed validation. You should test the success of the validation
|
|
|
|
|
with the :meth:`~django.forms.Form.is_valid()` method and not with the
|
|
|
|
|
presence or absence of the :attr:`~django.forms.Form.cleaned_data` attribute
|
|
|
|
|
on the form.
|
|
|
|
|
|
2012-07-16 03:07:02 +08:00
|
|
|
|
Miscellaneous
|
|
|
|
|
~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
* GeoDjango dropped support for GDAL < 1.5
|
|
|
|
|
|
2012-08-04 00:46:30 +08:00
|
|
|
|
* :func:`~django.utils.http.int_to_base36` properly raises a :exc:`TypeError`
|
|
|
|
|
instead of :exc:`ValueError` for non-integer inputs.
|
|
|
|
|
|
2012-03-30 17:33:51 +08:00
|
|
|
|
Features deprecated in 1.5
|
|
|
|
|
==========================
|
|
|
|
|
|
2012-04-30 01:58:00 +08:00
|
|
|
|
``django.utils.simplejson``
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
2012-04-30 02:33:54 +08:00
|
|
|
|
Since Django 1.5 drops support for Python 2.5, we can now rely on the
|
|
|
|
|
:mod:`json` module being in Python's standard library -- so we've removed
|
|
|
|
|
our own copy of ``simplejson``. You can safely change any use of
|
|
|
|
|
:mod:`django.utils.simplejson` to :mod:`json`.
|
2012-04-30 01:58:00 +08:00
|
|
|
|
|
|
|
|
|
``itercompat.product``
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~
|
2012-03-31 16:24:29 +08:00
|
|
|
|
|
|
|
|
|
The :func:`~django.utils.itercompat.product` function has been deprecated. Use
|
2012-05-24 19:02:19 +08:00
|
|
|
|
the built-in :func:`itertools.product` instead.
|
2012-08-12 20:39:48 +08:00
|
|
|
|
|
|
|
|
|
``django.utils.encoding.StrAndUnicode``
|
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
The :class:`~django.utils.encoding.StrAndUnicode` mix-in has been deprecated.
|
|
|
|
|
Define a ``__str__`` method and apply the
|
|
|
|
|
:func:`~django.utils.encoding.python_2_unicode_compatible` decorator instead.
|