#40 closed defect (fixed)
Attempt to set a many to many relation throws exception unless model specifies ordering.
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | |
Severity: | major | Keywords: | ManyToMany |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I've got two basic models, with a ManyToManyField connecting them. An exception is thrown while trying to set the relation:
class Foo(meta.Model) fields = ( meta.CharField('name', 'name', maxlength=100), ) class Bar(meta.Model) fields = ( meta.CharField('name', 'name', maxlength=100), meta.ManyToManyField(Foo), ) >>> f = foos.get_object(id__exact=1) >>> b = bars.get_object(id__exact=1) >>> f.set_bars((b.id,)) Traceback (most recent call last): File "<stdin>", line 1, in ? File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/core/meta.py", line 57, in _curried return args[0](*(args[1:]+moreargs), **dict(kwargs.items() + morekwargs.items())) File "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/django/core/meta.py", line 897, in method_set_related_many_to_many if rel_field.rel.orderable: AttributeError: ManyToMany instance has no attribute 'orderable'
If I add an "ordering = (('name', 'ASC'),)" to Bar then it works as expected.
The relation should work even without specifying an ordering, however orderable does not seem to be set at all unless I explicitly add ordering to the model.
Change History (2)
comment:1 by , 19 years ago
comment:2 by , 19 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Fixed in [157]. Thanks for the report! FYI, this was some legacy code from a previous Django incarnation that allowed for orderable many-to-many relations...We dropped support for that a couple of months back.
Actually, it doesn't work even if I set an ordering. I had to edit core/meta.py to remove the check for rel_field.rel.orderable