OK, had to think a bit for how this should be done.

What i've come up with is at http://www.sqlalchemy.org/trac/ticket/2658.   The 
good news is that you should be able to work around your issue right now if you 
just look at the state.deleted flag, which in the patch I'm adding a new helper 
function, but you can easily drop that in your code right now.

The object that's "deleted" in a flush but still not committed probably needs 
to stay associated with that Session, since it really is - if the transaction 
is rolled back, it goes back to persistent, and it's still present in the 
session.transaction._deleted list.  So in this state, it has state.session_key 
= <some key> but it also has state.deleted = True, which is basically "pending 
for committed deleted" state, which is really a whole object state in itself.   
After the commit, it should go to "detached", which is what the patch on that 
ticket accomplishes.  "detached" as you know means, "this object has 
corresponded to a row at some point, but we don't know if it does now".

But for the moment you can probably get what you need statewise by just looking 
at state.deleted.

I think it's not common that folks are tracking the state transitions on 
objects as closely as you do :).   At the moment I'd like to keep this for 0.8, 
just because we've been on 0.7 for a year with the current behavior and 0.8 
final has been in "any day now" status for several weeks (each new thing like 
this though makes me delay longer....).  Let me know what you think.




On Feb 1, 2013, at 10:53 AM, Michael Bayer wrote:

> that's definitely a bug and am looking into it.
> 
> if you *dont* delete the object, then it shows up as "detached" and all that 
> :)
> 
> 
> 
> On Feb 1, 2013, at 3:37 AM, Christian Theune wrote:
> 
>> Hi,
>> 
>> I'm trying to get my head around the attached scenario - unfortunately the 
>> documentation and aunt Google weren't too helpful :/
>> 
>> My expectation (up until now) was that an object that I mark as deleted 
>> would become useless for the application, similar to being detached after 
>> closing a session. If you run the attached code with SQLAlchemy (0.7 or 0.8) 
>> then the object stays alive, stays attached and the application can't see 
>> that it has been deleted.
>> 
>> Is this intentional? Am I holding it wrong?
>> 
>> Thanks,
>> Christian
>> 
>> -- 
>> 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 [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>> <sqlalchemy-issue.py>
> 
> 
> -- 
> 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 [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>  
>  

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to