#27365: Fields suddenly not found.
-------------------------------------+-------------------------------------
     Reporter:  Brandon              |                    Owner:  nobody
         Type:  Bug                  |                   Status:  closed
    Component:  Database layer       |                  Version:  1.9
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  needsinfo
     Keywords:  FieldDoesNotExist    |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Brandon):

 Further down the rabbit hole...

 After figuring out that it was  the occurance of {{{self.field_name ==
 self.name}}} that was producing the problem I instrumented
 {{{field_name}}} in {{{ForeignObjectRel}}}  so that I could compare it to
 {{{name}}}.
 Here is the instrumentation I added to {{{ForeignObjectRel}}}
 {{{
     def _set_field_name(self,value):
         name = getattr(self,'name',None)
         field_name = value
         if field_name and name and field_name == name:
             import traceback
             stacktrace = traceback.format_stack()
             message = ''.join(["Bug#27365 - self.field_name ==
 self.name\n"]+stacktrace)
             warnings.warn(message, RuntimeWarning, stacklevel=2)
         self._field_name=value
     def _get_field_name(self):
         name = getattr(self,'name',None)
         field_name = getattr(self,'_field_name',None)
         if field_name and name and field_name == name:
             import traceback
             stacktrace = traceback.format_stack()
             message = ''.join(["Bug#27365 - self.field_name ==
 self.name\n"]+stacktrace)
             warnings.warn(message, RuntimeWarning, stacklevel=2)
         return self._field_name
     field_name = property(_get_field_name,_set_field_name)
 }}}

 This allowed me to see if *anything* in the system was setting
 {{{self.field_name = self.name}}}, plus the exact trace to it in-situ.

 As it turns out, it seems an old 3rd party application that adds metadata
 to fields as attributes was reusing the attribute name {{{.field_name}}},
 unaware that django was using it. I believe that the introduction of the
 aggressive caching to relational objects that occurred between 1.7.x and
 1.9.x allowed this errant use of {{{.field_name}}} to persist all the way
 up until django attempted to reuse that object. Then when django reused
 the object, {{{self.field_name}}} had been *sometimes* been incorrectly
 set based on the caching + 3rd party app usage + life-time of the wsgi
 process.

 I have since deployed a monkey patch that alters the name of the metadata
 field used by the 3rd party application so that it does not collide with
 the relational object attribute {{{.field_name}}}.
 I have not seen the error since.

 --Brandon

--
Ticket URL: <https://code.djangoproject.com/ticket/27365#comment:12>
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/088.84abf8381f9e17af2061d4922519624d%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to