#2232 closed defect (fixed)
ManyRelatedManager is broken in certain conditions (can't get .all() from ManyToManyField)
Reported by: | Owned by: | Malcolm Tredinnick | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | |
Severity: | major | Keywords: | |
Cc: | Maniac@…, Malcolm Tredinnick | Triage Stage: | Unreviewed |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Looks like changeset 3195 has broken ManyToManyRelations. This simple code shows the problem:
class Article(models.Model): authors = models.ManyToManyField(Author) ... article = Article.objects.all()[0] article.authors.all() # Exception
The exception is
TypeError: Cannot resolve keyword 'article' into field
Attachments (1)
Change History (11)
comment:1 by , 19 years ago
Cc: | added |
---|
comment:2 by , 19 years ago
Summary: | ManyRelatedManager is broken (can't get .all() from ManyToManyField) → ManyRelatedManager is broken for cross-app relations (can't get .all() from ManyToManyField) |
---|
comment:3 by , 19 years ago
(In [3202]) Fixed #1796 -- only load a single copy of each model, even when it is
referenced via different import paths. Solves a problem with many-to-many
relations being set up incorrectly. Thanks to Curtis Thompson, Luke Plant and
Simon Willison for some excellent debugging of the problem. Refs #2232 (may
also have fixed that).
comment:5 by , 19 years ago
Cc: | added |
---|---|
Resolution: | fixed |
Status: | closed → reopened |
Summary: | ManyRelatedManager is broken for cross-app relations (can't get .all() from ManyToManyField) → ManyRelatedManager is broken in certain conditions (can't get .all() from ManyToManyField) |
Unfortunately this bug still appears even after 'abspath' fix in #1796. This makes me think that this is a separate issue. To summarize:
There are two models (simplified):
from django.contrib.auth.models import User as DjangoUser class Role(models.Model): slug = models.SlugField(unique=True) class User(models.Model): django_user = models.OneToOneField(DjangoUser) roles = models.ManyToManyField(Role, blank=True)
When running under dev server from the project's directory as current one by executing "./manage.py runserver" everything works fine.
When running under Apache with mod_python with these settings:
<Location "/"> SetHandler python-program PythonPath sys.path+['/usr/share/django','/home/maniac/project_parent'] PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE project_name.settings PythonDebug On </Location>
... then accessing user.roles.all() results in "Cannot resolve keyword 'user' into field"
Apache is running as "www-data" user, dev server as my local user.
I'm absolutely at loss where to start thinkning about it...
comment:6 by , 19 years ago
Owner: | changed from | to
---|---|
Status: | reopened → new |
comment:7 by , 19 years ago
The partial fix I just attached fixes part of the problem. I found another way we were creating two instances of a model. Can you try it out and see if it helps in your setup?
comment:8 by , 19 years ago
Yes, looks fixed with the patch. Checked both Apache and dev server this time.
P.S. I look forward to reading your promised explanation in the wiki. This whole issue seems to me a bit fragile, may be there should be some more robust way of registering apps...
comment:9 by , 19 years ago
comment:10 by , 19 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
As far as I can see, [3212] should have fixed the last problem in this area. Closing now.
Testing it a bit further shows that this fails only in this two cases: