I'm pretty sure I've hit some sort of weird bug in SA's ORM module. I have a database which is autoreflected (sorry), and one of the tables is self-referential via foreign-key. Additionally, there is a database default and a NOT NULL constraint. This relationship is described as a relation named "children" with a backref called "parent" (in this case I am specifying the remote_side) and there is *NOT* a post_update on this relationship.
The typical usage pattern for me looks like this: o = Object() o.attribute1 = some_value o.parent = o sess.add(o) sess.flush() However, I've noticed that the parent attribute is completely ignored, or seems to be. OK, partly that is due to the absence of a post_update field. Since the database has a default the insert works (although I would suggest that SA might consider grumping under circumstances like this). So I tried this: o = Object() o.attribute1 = some_value o.parent = o sess.add(o) sess.flush() o.parent = o sess.flush() And no subsequent UPDATE takes place (because SA doesn't know that the .parent relationship is wrong). This seems to me to be a bug. There are two ways to "fix" the problem: If I issue a sess.refresh(o) after the first flush() then everything works as expected. If I use o.children = [ o ] then SA issues a query for objects of that nature and /then/ then the second flush will work. It seems to me that since SA won't act on that relationship at INSERT time without post_update=True this causes SA to have the wrong data in the parent/child relationship - in reality it is some other value but SA doesn't know that. It's almost as if the lack of post_update=True somehow causes SA to forget that the data defining that relationship is (probably) wrong. As a side note, perhaps SA could grump about accessing a relationship of this nature *before* a concrete example of the instance exists? -- Jon --~--~---------~--~----~------------~-------~--~----~ 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 sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---