#1796: [patch] "Cannot resolve keyword ___ into field" error when working with
ManyToMany relation
-------------------------+--------------------------------------------------
Reporter: anonymous | Owner: mtredinnick
Status: reopened | Component: Database wrapper
Version: SVN | Resolution:
Keywords: | Stage: Accepted
Has_patch: 0 | Needs_docs: 0
Needs_tests: 0 | Needs_better_patch: 0
-------------------------+--------------------------------------------------
Changes (by brantley <[EMAIL PROTECTED]>):
* cc: [EMAIL PROTECTED] (added)
Comment:
I'm not sure where everyone is on this but I figured it out for me so I
thought I'd share:
The problem is that the get_all_related_many_to_many_objects() caches
itself, so if the many-to-many manager gets called before all the apps are
loaded, any models in apps added afterwards won't be in that cache. I
commented out the line that gets the cache so it has to re-cache each
time, and it fixes the problem. Behold:
{{{
def get_all_related_many_to_many_objects(self):
try: # Try the cache first.
return self.ham_sandwich
#return self._all_related_many_to_many_objects
except AttributeError:
...
}}}
Since .ham_sandwich is never found it falls into the AttributeError
exception and re-caches. It then works as planned.
The permanent fix, it seems to me, is to make it so that when a many-to-
many is created, it clears the _all_related_many_to_many_objects of the
_meta of the relation class, but I'm not sure exactly where best to do
that.
--
Ticket URL: <http://code.djangoproject.com/ticket/1796#comment:75>
Django Code <http://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 post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---