I added logging to `session.transaction` and `session.transaction.parent` 
(til parent=None) and `session.transaction.nested` and they all seemed to 
be different, never nested, never subtransaction. No hint there.

I modified my code slightly by adding a new 
`celery_state_session.query(CeleryState)` followed by another 
`celery_state_session.commit()` right after the original 
`celery_state_session.commit()` (Remember there is no 
`celery_state_session.close()` nor `eng.dispose()` after commit).

When the TransactionRollbackError is caught, the SQL log shows the 
following:

*ROLLBACK* *<<<< can't tell but I think this is from the 
`domain_model_session` due to TransactionRollbackError*
select version()
{}
select current_schema()
{}
SELECT CAST(...)
{}
SELECT CAST(...)
{}
show standard_conforming_strings
{}
BEGIN (implicit)
SELECT celery_state ...
*<<<<< NO UPDATE even though I just changed celery_state*
COMMIT
BEGIN (implicit)
SELECT celery_state ... *<<<< SHOWS unchanged values ("of course" there was 
no UPDATE)*
COMMIT

When the domain model transaction succeeds, the SQL looks correct:

*COMMIT* *<<<< can't tell but I think this is from the 
`domain_model_session`*
select version()
{}
select current_schema()
{}
SELECT CAST(...)
{}
SELECT CAST(...)
{}
show standard_conforming_strings
{}
BEGIN (implicit)
SELECT celery_state ...
*UPDATE celery_state <<<< Yay!*
COMMIT
BEGIN (implicit)
SELECT celery_state ... *<<<< SHOWS NEW values ("of course")*
COMMIT

Perhaps psycorpg2? 

Maybe because I create a new engine and session for each checkpoint? (and 
never dispose it nor close it?)

Seems like the ROLLBACK from the domain_model_session/engine makes the 
changes on the celery_state_session/eng be "skipped"?

Is there any way I can log the issuer (connection, engine, session, thread, 
*process-id/pid*, whatever) of each SQL statement?

The weird thing is that the checkpoint that always works is the first one 
(started). The last one only works when the domain model transaction 
succeeds. Any intermediate one never works.

SELECT * FROM pg_stat_activity shows many, some in COMMIT and some in 
ROLLBACK; all wait_event_type = Client and wait_event = ClientRead


-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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.

Reply via email to