unique=True on model behave strangely when there is a ListField in the model
gregtap opened this issue · comments
Hi,
I found something strange when I try to save an instance which as a unique Attribute field email and a List of Reference fields rooms_visited.
As soon as I add an entry to my list the save() of my instance fails on the uniqueness of the Attribute field 'email'.
Strangely, I am able to update the email field then save() without problems.
Removing unique=True works and I only have one user created, not two.
from redisco import models
import string
import redisco
redisco.connection_setup(host='localhost', db=5)
class UserRoomVisit(models.Model):
code = models.Attribute(required=True)
joined_date = models.DateTimeField(auto_now_add=True)
class User(models.Model):
# for some reasons unique True fails to validate on save !
email = models.Attribute(required=True, indexed=True, unique=True)
rooms_visited = models.ListField(UserRoomVisit)
class Room(models.Model):
code = models.Attribute(required=True, indexed=True, unique=True)
owner = models.ReferenceField(User)
u = User(email="foo@gmail.com")
u.save()
r = Room(owner=u, code="xxx")
r.save()
e = UserRoomVisit(code="xxx")
e.save()
print u # <User:1 {'rooms_visited': [], 'email': 'foo@gmail.com'}>
u.rooms_visited.append(e)
print u # <User:1 {'rooms_visited': [<UserRoomVisit:1 {'joined_date': datetime.datetime(2012, 10, 5, 19, 26, 55, 382587), 'code': 'ppp'}>], 'email': 'foo@gmail.com'}>
errors = u.save()
print errors # [('email', 'not unique')]