#20393: django.db.models.query.QuerySet.__repr__ should not have side-effects
-------------------------------------+-------------------------------------
Reporter: justin@… | Owner: nobody
Type: Uncategorized | Status: new
Component: Database layer | Version: 1.4
(models, ORM) | Keywords: QuerySet, repr, side-
Severity: Normal | effect
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
In trying to track down some timeouts and strange queries in our apps we
saw some strange queries being run by django. We were querying for a
single record with a FOR UPDATE, getting an error, then django would run
the same query 3 times but with a limit of 21 and then fetch all of the
records, each time.
Eventually I tracked this down to our error-handling middleware calling
repr() on a QuerySet, which then queried the database. `__repr__` is
supposed to be a string-representation of an object in its current state
and should not gave side-effects like making database queries, especially
in the case where the query uses FOR UPDATE or similar logic.
I suggest changing `django.db.models.query.QuerySet.__repr__` to only
touch the cached records and not use the local iterator, which can and
will query the DB, potentially causing issues like this.
--
Ticket URL: <https://code.djangoproject.com/ticket/20393>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.