Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #22349 -- Added a note clarifying `RawQuerySet` has no `__len__`.

Thanks cdestigter for the report.
  • Loading branch information...
commit 2d425116e2f26ab546c380784df1de79562009a7 1 parent 3861669
@mmardini mmardini authored timgraham committed
Showing with 14 additions and 1 deletion.
  1. +1 −0  AUTHORS
  2. +13 −1 docs/topics/db/sql.txt
View
1  AUTHORS
@@ -422,6 +422,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>
View
14 docs/topics/db/sql.txt
@@ -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::
@@ -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
------------------------------------
Please sign in to comment.
Something went wrong with that request. Please try again.