Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to run code after changes are committed? #817

Unanswered
plaa asked this question in Q&A
Discussion options

We have a project using Gino, where a DB transaction is started on router layer (or similar) and feature layer code is called that does DB updates without knowing about the transaction. We now have a need to run code from the feature layer after the changes made are committed to the DB.

SQLAlchemy ORM has after_commit and similar hooks which can be used for this purpose, but I was unable to find any commit hooks in Gino. Does Gino have this kind of support? How would you suggest handling it?

You must be logged in to vote

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
Comment options

The listens_for requires an SQLAlchemy engine to be passed to it. What should I pass it?

I'm able to bind to the global engine:

from sqlalchemy.engine import Engine
async with db.transaction() as tx:
 @event.listens_for(Engine, "commit")
 def receive_commit(conn):
 # do something

but this is triggered for any commit and they build up, the listening is never released. Is there a way to listen to the commit of the current transaction, and nothing later?

I have access to the db = gino.Gino() object and have tried passing various properties but nothing else has worked at all. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /