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.
* 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>
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>
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>
* 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>
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>
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>