feat: turn off autoflush on integration tests#30394
Closed
betodealmeida wants to merge 2 commits intomasterfrom
Closed
feat: turn off autoflush on integration tests#30394betodealmeida wants to merge 2 commits intomasterfrom
betodealmeida wants to merge 2 commits intomasterfrom
Conversation
| # many integration tests write and read in the same session, and because by default | ||
| # SQLAlchemy uses autoflush, the test would see data that in real world wouldn't be | ||
| # there. | ||
| db.session.configure(autoflush=False) |
Member
There was a problem hiding this comment.
QQ: would this be needed/preferred on the tests/unit_tests/ side of the house too? If so it could be great to factor out into tests/common/ (?)
Member
There was a problem hiding this comment.
just that one question, otherwise PR LGTM
geido
approved these changes
Oct 1, 2024
Member
|
@betodealmeida Another idea would be to keep autoflush in our tests and check the session for pending commits/rollbacks after our tests run. This can be done globally and would work for current and new code. |
Member
|
Are we still intending to get this merged? Converting to draft since it's been inactive for a while and is in need of a rebase. |
e079aa6 to
5309aaa
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SUMMARY
#24969 introduced the
@transactiondecorator, to be used in commands to ensure that commits are explicit and happen only once in the lifetime of a request, preventing eagers commits. The PR failed to catch a few cases where legacy API endpoints were not using commands, resulting in successful requests that wouldn't be persisted to the database. These were fixed in #30215.Why did our integration tests fail to catch these endpoints that were not committing? Tests failed because by default SQLAlchemy will autoflush before running a
SELECT. In real world, favoriting a chart and verifying that it was favorited are two separate requests. If the first one fails to commit, the second one won't see a change. But our integration tests share the same global session (db.session), so that an insert followed by a select will result in flush between them, and the non-committed data will be seen even though we useREAD COMMITTEDas the isolation level.To prevent this from happening again, this PR turns off the autoflush in the integration tests.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION