#20278 closed Bug (fixed)
Passing self to object query may cause infinite regression
Reported by: | anonymous | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 1.5 |
Severity: | Release blocker | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
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)
Change History (6)
comment:1 by , 12 years ago
Component: | Uncategorized → Database layer (models, ORM) |
---|---|
Easy pickings: | set |
Severity: | Normal → Release blocker |
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Bug |
comment:2 by , 12 years ago
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 {}.
comment:3 by , 12 years ago
Ah, good point about MultipleObjectsReturned
. Yes, I agree that we should remove that too, for the same reason.
comment:4 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
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.