2 Jan 2011 03:52
change of discriminator column apparently not saved by session?
Eric Ongerth <ericongerth <at> gmail.com>
2011-01-02 02:52:00 GMT
2011-01-02 02:52:00 GMT
I must be doing something wrong but can't find it. I'm doing some database refactoring and found a situation where I had to set up a joined-table inheritance structure after the fact, with some of the tables already populated. I created (successfully) a script that got all of the primary and foreign keys right on all the child tables and the parent table, and now I just need to correctly populate the discriminator column on the parent table. Each row of the parent table is referenced by exactly one row from one of the six child tables. So i'm iterating through all child objects (yes, doing this via the sa ORM) and setting the value of the discriminator appropriately. Then I commit the Session. Afterward, I go and look at the parent table directly using pgAdmin and I see that the new values in the discriminator column were not saved. That's strange because I didn't get an error either, nor am I doing anything that would mask an error. So I thought maybe the discriminator column on the parent table in a joined-table inheritance scenario is just not watched by the Session / UOW. I thought maybe it assumes that this column would only, normally, be set during object instantiation and would typically not change for the lifetime of the object and its associated database rows. So I tried manually dirtying the object using instance_state(obj).modified=True before committing the Session. Still no success, the new values don't get saved. Is going outside of the ORM the only way to get this done? I don't mind doing so, but I'm just trying to understand better why my initial/ intuitive approach didn't do the job.(Continue reading)
RSS Feed