Opened 14 years ago

Closed 14 years ago

Last modified 12 years ago

#40 closed defect (fixed)

Attempt to set a many to many relation throws exception unless model specifies ordering.

Reported by: jforeman@… 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


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),

>>> f = foos.get_object(id__exact=1)
>>> b = bars.get_object(id__exact=1)
>>> f.set_bars((,))
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/", 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/", 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 Changed 14 years ago by jforeman@…

Actually, it doesn't work even if I set an ordering. I had to edit core/ to remove the check for rel_field.rel.orderable

comment:2 Changed 14 years ago by Adrian Holovaty

Resolution: fixed
Status: newclosed

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.

Note: See TracTickets for help on using tickets.
Back to Top