django-ondelta icon indicating copy to clipboard operation
django-ondelta copied to clipboard

TypeError: add() argument after * must be a sequence, not RelatedManager

Open smcoll opened this issue 10 years ago • 3 comments

Here are the models:

class Foo(OnDeltaModel):
    name = models.CharField(max_length=50)
    is_public = models.BooleanField(default=False)

class Bar(models.Model):
    foo = models.ForeignKey(models.Model, related_name='items'):

And the traceback:

>>> foo.save()
Traceback (most recent call last):
  File "[...]python2.7/site-packages/IPython/core/interactiveshell.py", line 2827, in run_code
    exec code_obj in self.user_global_ns, self.user_ns
  File "<ipython-input-10-6970514bfc33>", line 1, in <module>
    c.save()
  File "[...]python2.7/site-packages/ondelta/models.py", line 75, in save
    self._ondelta_dispatch_notifications()
  File "[...]python2.7/site-packages/ondelta/models.py", line 55, in _ondelta_dispatch_notifications
    setattr(self._ondelta_shadow, field, changes['new'])
  File "[...]python2.7/site-packages/django/db/models/fields/related.py", line 404, in __set__
    manager.add(*value)
TypeError: add() argument after * must be a sequence, not RelatedManager

It happens because 'items' returns as a field name in the _ondelta_fields_to_watch() method of Foo, although it's not a field. django.db.models.options.get_all_field_names() includes reverse relation names.

smcoll avatar Jan 12 '15 18:01 smcoll

Thanks for opening this I'll dive into it over the next few days.

adamhaney avatar Jan 13 '15 03:01 adamhaney

https://github.com/adamhaney/django-ondelta/pull/6 seemed to fix this; confirm?

smcoll avatar Apr 16 '15 20:04 smcoll

Although, to support Django 1.8, we'll need to implement _meta.get_fields() instead: https://docs.djangoproject.com/en/1.8/ref/models/meta/#django.db.models.options.Options.get_fields

smcoll avatar Apr 16 '15 20:04 smcoll