Skip to content

Commit

Permalink
[1.9.x] Fixed #26526 -- Documented QuerySet.latest()'s dependency on …
Browse files Browse the repository at this point in the history
…database ordering.

Backport of e6c5e68 from master
  • Loading branch information
Chad Shryock authored and timgraham committed Jun 2, 2016
1 parent 95ed151 commit 9d52cdf
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions docs/ref/models/querysets.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1954,6 +1954,17 @@ given parameters.
Note that ``earliest()`` and ``latest()`` exist purely for convenience and
readability.

.. admonition:: ``earliest()`` and ``latest()`` may return instances with null dates.

Since ordering is delegated to the database, results on fields that allow
null values may be ordered differently if you use different databases. For
example, PostgreSQL and MySQL sort null values as if they are higher than
non-null values, while SQLite does the opposite.

You may want to filter out null values::

Entry.objects.filter(pub_date__isnull=False).latest('pub_date')

``earliest()``
~~~~~~~~~~~~~~

Expand Down

0 comments on commit 9d52cdf

Please sign in to comment.