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

-- 
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to