Hi guys, i cant seem to find out whats causing this.

first, here are my classes:

class User(Base):
    __tablename__ = "users"
    id = Column(GUID, primary_key=True, default=uuid.uuid4())
    ....
    
    permissions = ("Permission", secondary=UserPermission.__table__)

class Permission(Base):
    __tablename__ = "permissions"
    id = Column(GUID, primary_key=True, default=uuid.uuid4())
    ....

class UserPermission(Base):
    __tablename__ = "user_permissions"
    id = Column(GUID, primary_key=True, default=uuid.uuid4())
    user_id = Column(GUID, ForeignKey('users.id'), nullable=False)
    permission_id = Column(GUID, ForeignKey('permissions.id'), 
nullable=False)


Then, lets say I queried an exising user:
user = Session.query(User).filter(User.username == 'johndoe').first()

And then i added some permissions to the user
user.append(permission1)
user.append(permission2)
user.append(permission3)

Session.add(user)
Session.commit()

and what i got is 

IntegrityError: (IntegrityError) duplicate key value violates unique constraint 
"pk_user_permissions"

because on the insert statement all the id generated were all the same.


and to clarify the GUID is the recipe 
from 
http://docs.sqlalchemy.org/en/rel_0_9/core/types.html#backend-agnostic-guid-type


anyone have any idea?

Thanks in advance


-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to