Skip to content

Commit

Permalink
[1.7.x] Fixed #22349 -- Added a note clarifying RawQuerySet has no …
Browse files Browse the repository at this point in the history
…`__len__`.

Thanks cdestigter for the report.

Backport of 2d42511 from master
  • Loading branch information
mmardini authored and timgraham committed Jun 12, 2014
1 parent d9eef1f commit d3bf537
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -419,6 +419,7 @@ answer newbie questions, and generally made Django that much better:
Javier Mansilla <javimansilla@gmail.com>
masonsimon+django@gmail.com
Manuzhai
Moayad Mardini <moayad.m@gmail.com>
Petr Marhoun <petr.marhoun@gmail.com>
Petar Marić <http://www.petarmaric.com/>
Nuno Mariz <nmariz@gmail.com>
Expand Down
14 changes: 13 additions & 1 deletion docs/topics/db/sql.txt
Expand Up @@ -33,7 +33,8 @@ return model instances:

This method takes a raw SQL query, executes it, and returns a
``django.db.models.query.RawQuerySet`` instance. This ``RawQuerySet`` instance
can be iterated over just like a normal QuerySet to provide object instances.
can be iterated over just like a normal
:class:`~django.db.models.query.QuerySet` to provide object instances.

This is best illustrated with an example. Suppose you have the following model::

Expand Down Expand Up @@ -84,6 +85,17 @@ options that make it very powerful.
both rows will match. To prevent this, perform the correct typecasting
before using the value in a query.

.. warning::

While a ``RawQuerySet`` instance can be iterated over like a normal
:class:`~django.db.models.query.QuerySet`, ``RawQuerySet`` doesn't
implement all methods you can use with ``QuerySet``. For example,
``__bool__()`` and ``__len__()`` are not defined in ``RawQuerySet``, and
thus all ``RawQuerySet`` instances are considered ``True``. The reason
these methods are not implemented in ``RawQuerySet`` is that implementing
them without internal caching would be a performance drawback and adding
such caching would be backward incompatible.

Mapping query fields to model fields
------------------------------------

Expand Down

0 comments on commit d3bf537

Please sign in to comment.