[Django] #20278: Passing self to object query may cause infinite regression

10 views
Skip to first unread message

Django

unread,
Apr 17, 2013, 11:35:33 AM4/17/13
to django-...@googlegroups.com
#20278: Passing self to object query may cause infinite regression
-------------------------------+--------------------
Reporter: anonymous | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.5
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
This commit introduced passing the kwargs to the DoesNotExist Query
Exception:

https://github.com/django/django/commit/d5b93d3281fe93cbef5de84a52

This involves a call of the __unicode__() method on the given query
objects and may lead to an infinity regression, if the __unicode__ method
depends on the same query.

The error occured in my custom translation system:

{{{

class Model:

(...)

def defaultTranslation(self):
"""
:return: ModelTranslation
"""
try:
defaultTranslation = ModelTranslation.objects.get(base=self,
language__code=settings.FALLBACK_LANGUAGE)
except ObjectDoesNotExist:
raise CustomException('Model {0} does not have a default
translation.'.format(str(self.id)))
return defaultTranslation

def __unicode__(self):
try:
return self.defaultTranslation.name
except CustomException:
return self.abbreviation
}}}

Changing the query to reference the id fixes the problem.


{{{
defaultTranslation =
ModelTranslation.objects.get(base_id=self.id,
language__code=settings.FALLBACK_LANGUAGE)

}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/20278>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 17, 2013, 11:40:50 AM4/17/13
to django-...@googlegroups.com
#20278: Passing self to object query may cause infinite regression
-------------------------------------+-------------------------------------
Reporter: anonymous | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.5
(models, ORM) | Resolution:
Severity: Release blocker | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by carljm):

* severity: Normal => Release blocker
* needs_better_patch: => 0
* component: Uncategorized => Database layer (models, ORM)
* needs_tests: => 0
* easy: 0 => 1
* needs_docs: => 0
* type: Uncategorized => Bug
* stage: Unreviewed => Accepted


Comment:

Verified - accepting and marking release blocker, since this is a
regression in 1.5.

I think the correct fix is to simply roll back
https://github.com/django/django/commit/d5b93d3281fe93cbef5de84a52 -
there's just too much risk in triggering arbitrary `__unicode__` methods
(that can do just about anything) deep in the guts of an ORM query
execution, it's not worth the debugging benefits of that commit.

--
Ticket URL: <https://code.djangoproject.com/ticket/20278#comment:1>

Django

unread,
Apr 17, 2013, 12:08:30 PM4/17/13
to django-...@googlegroups.com
#20278: Passing self to object query may cause infinite regression
-------------------------------------+-------------------------------------
Reporter: anonymous | Owner: nobody

Type: Bug | Status: new
Component: Database layer | Version: 1.5
(models, ORM) | Resolution:
Severity: Release blocker | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 1 |
-------------------------------------+-------------------------------------

Comment (by akaariai):

Interestingly the kwargs were passed to MultipleObjectsReturned even
before my commit. So, changing that too seems like a good idea.

BTW the exception message isn't that useful anyways. The get parameters
alone aren't good enough, the whole condition used by the query could be
useful. This is really clear when using .latest() for example, this can
result in DoesNotExist exception with lookup parameters of {}.

--
Ticket URL: <https://code.djangoproject.com/ticket/20278#comment:2>

Django

unread,
Apr 17, 2013, 12:16:12 PM4/17/13
to django-...@googlegroups.com
#20278: Passing self to object query may cause infinite regression
-------------------------------------+-------------------------------------
Reporter: anonymous | Owner: nobody

Type: Bug | Status: new
Component: Database layer | Version: 1.5
(models, ORM) | Resolution:
Severity: Release blocker | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 1 |
-------------------------------------+-------------------------------------

Comment (by carljm):

Ah, good point about `MultipleObjectsReturned`. Yes, I agree that we
should remove that too, for the same reason.

--
Ticket URL: <https://code.djangoproject.com/ticket/20278#comment:3>

Django

unread,
May 20, 2013, 11:50:40 AM5/20/13
to django-...@googlegroups.com
#20278: Passing self to object query may cause infinite regression
-------------------------------------+-------------------------------------
Reporter: anonymous | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: 1.5
(models, ORM) | Resolution: fixed

Severity: Release blocker | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 1 |
-------------------------------------+-------------------------------------
Changes (by Anssi Kääriäinen <akaariai@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"266c0bb23e9d64c47ace4d162e582febd5a1e336"]:
{{{
#!CommitTicketReference repository=""
revision="266c0bb23e9d64c47ace4d162e582febd5a1e336"
Fixed #20278 -- ensured .get() exceptions do not recurse infinitely

A regression caused by d5b93d3281fe93cbef5de84a52 made .get() error
reporting recurse infinitely on certain rare conditions. Fixed this by
not trying to print the given lookup kwargs.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/20278#comment:4>

Django

unread,
May 20, 2013, 11:52:23 AM5/20/13
to django-...@googlegroups.com
#20278: Passing self to object query may cause infinite regression
-------------------------------------+-------------------------------------
Reporter: anonymous | Owner: nobody

Type: Bug | Status: closed
Component: Database layer | Version: 1.5
(models, ORM) | Resolution: fixed
Severity: Release blocker | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 1 |
-------------------------------------+-------------------------------------

Comment (by Anssi Kääriäinen <akaariai@…>):

In [changeset:"0eddedf7db782a05e098c7024a9056aef7283b81"]:
{{{
#!CommitTicketReference repository=""
revision="0eddedf7db782a05e098c7024a9056aef7283b81"
[1.5.x] Fixed #20278 -- ensured .get() exceptions do not recurse
infinitely

A regression caused by d5b93d3281fe93cbef5de84a52 made .get() error
reporting recurse infinitely on certain rare conditions. Fixed this by
not trying to print the given lookup kwargs.

Backpatch of 266c0bb23e9d64c47ace4d162e582febd5a1e336
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/20278#comment:5>

Django

unread,
Nov 20, 2014, 4:27:05 PM11/20/14
to django-...@googlegroups.com
#20278: Passing self to object query may cause infinite regression
-------------------------------------+-------------------------------------
Reporter: anonymous | Owner: nobody

Type: Bug | Status: closed
Component: Database layer | Version: 1.5
(models, ORM) | Resolution: fixed
Severity: Release blocker | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 1 |
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"d8f00e1918ce4df76920f3d79bc8d805fa69e29e"]:
{{{
#!CommitTicketReference repository=""
revision="d8f00e1918ce4df76920f3d79bc8d805fa69e29e"
Added a comment for test of refs #20278.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/20278#comment:6>

Reply all
Reply to author
Forward
0 new messages