On Tuesday, February 23, 2016 at 5:44:45 PM UTC+1, Mike Bayer wrote: Mike, thank you for your reply and help.
well the first thing is you definitely don't need > UniqueConstraint('lang_id', 'text_id') because these columns are already > in the primary key. > Noted. > the next issue in this test at least is that you're referring to the > primary key of a row in Lang but there is no Lang row being created > here. SQLite will let you put the invalid primary key into lang_id but > only because foreign keys aren't enforced by default. > I did not know foreign keys are not enforced by default by SQLite; thanks for information. Indeed I did not copy code which creates Lang objects to this test from my project. then the reason for the error is that TextValue objects are potentially > being replaced but the mapping is not emitting a delete for the old > TextValue, so you'd need to put cascade="all, delete-orphan" on the > Text._values relationship so that when you assign a new dictionary > value, the old TextValue objects are deleted. > That the old TextValue objects need to be deleted I understand. What I don't see is what makes SA specifically blank-out primary key column 'text_value.text_id'? Asking differently; I would understand if I got some integrity errors while SA would be trying to insert new rows with the same keys without first deleting old rows but I have no idea how SA "came up with the idea" to blank-out primary key? > In this specific example, marking the TextValue as deleted ends up gving > you an UPDATE of TextValue, because the ORM converts an INSERT/DELETE of > the same primary key into a single UPDATE. But if your dictionary Is this an implementation detail or official semantics? It's very important for me to keep identity of existing TextValue objects and only update values in their 'value' column. (The reason it's important is that I'm using sqlalchemy-continuum extension for automatic versioning). Is there some preferred way to make sure identity is intact and modifications are done through UPDATE and not DELETE/INSERT? Also, you say that in this specific example there is no DELETE needed yet there's an error. Does it mean SA tries to make sure DELETEs would be possible if they were needed even if in this specific example they are not needed? Regards, Piotr -- 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 sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.