Skip to content
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

Using session.add() in execution stage of flush warning #294

Open
AbdealiLoKo opened this issue Aug 26, 2022 · 2 comments
Open

Using session.add() in execution stage of flush warning #294

AbdealiLoKo opened this issue Aug 26, 2022 · 2 comments

Comments

@AbdealiLoKo
Copy link
Contributor

AbdealiLoKo commented Aug 26, 2022

I got a part of my code to use sqlalchemy-continuum after a figuring out a bunch of stuff
When I ran my unit tests, I got this warning 800+ times:

00:21:29.767   /io/venv/lib/python3.6/site-packages/sqlalchemy_continuum/unit_of_work.py:123: SAWarning:
00:21:29.767   
00:21:29.767   Usage of the 'Session.add()' operation is not currently supported within the execution stage of the flush process. Results may not be consistent.  Consider using alternative event listeners or connection-level operations instead.

On checking, it seems this warning has been there in sqlalchemy since the past 10+ years (since sqlalchemy 0.8)
sqlalchemy/sqlalchemy@1c3e3225521647cc843a633e34ed84e1ca4e797aj

I'm wondering if I am using sqla-continuum wrongly ? Or is it expected ?

@marksteward
Copy link
Collaborator

marksteward commented Aug 26, 2022

This should only happen before flush, outside a transaction:

    def process_before_flush(self, session):
...
        if not self.current_transaction:
            self.create_transaction(session)
...
        session.add(self.current_transaction)

If you're seeing this message, I suspect something is incorrectly changing the state of the transaction, perhaps re-entry of some kind. Can you create a minimal complete reproduction for this warning?

@AbdealiLoKo
Copy link
Contributor Author

Yep. Will try to create a example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants