I've drilled down all the way up to `mapper._save_obj()`. I examined the `state.dict` for `qitem`.
Good case: qitem state dict = {'campaign': <Campaign 233, u'Test'>, 'campaign_id': 233, ...} And for the bad case: qitem state dict = {'campaign': <Campaign 234, u'Test'>, 'campaign_id': None, ...} The `campaign` property is *relation* to `Campaign` entity. Campaign is previously flushed and has id. But, for some reason the `campaign_id` is missing inside `qitem` state event though the `campaign` is present. I can probably work around by saying: qitem.campaign_id = campaign.id but then I must rely on campaign being flushed which might not allways be the case. Yes, I can flush it manually, but I like to depend on relations functioning properly. P.S. I am not restarting or changing application in any way, just refreshing a web page, which sometime fails and sometime succeeds. -- 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.