The example below raises an:
sqlalchemy.exceptions.AssertionError: Dependency rule tried to blank-
out primary key column 'userdata.user_id' on instance
'[EMAIL PROTECTED]'

The code creates 2 objects having a 1:1 relation with cascade-delete.
The ForeignKey is declared as a primary key. This seems to cause the
Error.
Versions: Python 2.4, SA 0.3.1, SA 0.3.4


class User(object):
        pass

class Userdata(object):
        def __init__(self, user):
                self.user_id = user.id

if __name__=="__main__":
        db = create_engine("mysql://[EMAIL PROTECTED]/test_cascade")
        session = create_session()
        metadata = BoundMetaData(db)

        t_user = Table("user",metadata,
                Column("id",Integer,primary_key=True),
                )
        t_userdata = Table("userdata",metadata,
                
Column("user_id",Integer,ForeignKey("user.id"),primary_key=True),
                )
        metadata.create_all()
        mapper(User, t_user)
        mapper(Userdata, t_userdata, properties = {
                "myuser":relation(User,backref=backref("meta",cascade="delete"))
                })

        # create 1 instance of each object:
        user1 = User()
        session.save(user1)
        session.flush()
        data1 = Userdata(user1)
        session.save(data1)
        session.flush()

        # now delete the user,
        # expecting the cascade to delete userdata,too:
        session.delete(user1)
        session.flush() #AssertionError: Dependency rule tried to blank-
out ...


I can workaround this error by using a separate primary key in table
userdata:
        t_userdata = Table("userdata",metadata,
                Column("id",Integer,primary_key=True),
                Column("user_id",Integer,ForeignKey("user.id")),
                )
and everything works fine.
I'm wondering whether this is an SA bug, or a bad table design ?
Thanks and regards,
 Ruben


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to