-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Transaction Events #29
Comments
Thanks for reporting! This is definitely something that could be improved. Updating the docs would help but beyond just having an example of Something like: db = SQLClient()
db.subscribe_session('before_commit', callback)
db.subscribe_engine('connect', callback)
# or maybe just db.subscribe() that automaps event name to session or engine
db.subscribe(...) Thoughts? |
I really like the way you wrapped SA's event API so the event callbacks can live in the model definition, keeping everything together (as per the example here). Keeping this style, but without requiring devs to extend the SQLClient() class, what do you think about something like: db = SQLClient()
@db.listen('before_commit')
def pre_commit(client):
print("Session 'before_commit' event")
#or maybe, explicit decorator per event name, rather than SA's string arg approach?
@db.before_commit
def pre_commit(client):
print("Session 'before_commit' event") |
I like where you're going with that but with a small tweak to mirror @db.listens_for('before_commit')
def pre_commit(...)
db.listen('before_commit', pre_commit) which would match As for the named event decorators, those could be useful too but might potentially namespace them to But as a first iteration, I think just having |
Hi Derrick,
I was using SQLAlchemy session events to run some code on the "before_commit" event. For example:
If you try and use an SqlClient instance as the first argument to even.listen(), you get:
I managed to get around this by using the _Session. Working code follows:
It took a little time to figure out the above because your docs are specific to ORM events. I can see a couple of options to help others in the future but wanted to get your thoughts before taking it further:
The text was updated successfully, but these errors were encountered: