redisco icon indicating copy to clipboard operation
redisco copied to clipboard

ListFields don't seem to work with inherited classes

Open tonycpsu opened this issue 12 years ago • 1 comments

It looks to me like one can define subclasses that inherit fields from the parent classes, but I'm running into a problem when I use them. Here's a trivial example of what I'm seeing:

>>> from redisco import models
>>> class Person(models.Model):
...     name = models.Attribute(required=True)
...
>>> class CoolPerson(Person):
...     coolness = models.IntegerField(required=True)
...
>>> class People(models.Model):
...     members = models.ListField(Person)
...
>>> people = People()
>>> alice = Person(name="Alice")
>>> alice.save()
True
>>> print alice
<Person:1 {'name': 'Alice', 'id': '1'}>
>>> people.members.append(alice)
>>> people.save()
True
>>> print People.objects.all()
[<People:1 {'id': '1', 'members': [<Person:1 {'name': u'Alice', 'id': '1'}>]}>]
>>> bob = CoolPerson(name="Bob", coolness=6)
>>> bob.save()
True
>>> print bob
<CoolPerson:1 {'coolness': 6, 'name': 'Bob', 'id': '1'}>
>>> people.members.append(bob)
>>> people.save()
True
>>> print People.objects.all()
[<People:1 {'id': '1', 'members': [<Person:1 {'name': u'Alice', 'id': '1'}>, <Person:1 {'name': u'Alice', 'id': '1'}>]}>]
>>>

I would expect the last line to show Bob as a member, but instead Alice is shown twice.

tonycpsu avatar Feb 15 '13 22:02 tonycpsu

Well spotted. This comes from the fact that we only store ID's and nothing related to the actual instance. Later, when we refetch the objects, we use the class reference to recreate the object.

This bug will need a clear refactoring of Lists.

kiddouk avatar Feb 24 '13 15:02 kiddouk