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

Fix flaky. Workaround for SQLite driver bug returning a result before the commit. #657

Merged
merged 3 commits into from
Sep 6, 2024

Conversation

lizardoluis
Copy link
Collaborator

@lizardoluis lizardoluis commented Sep 6, 2024

There is a bug on SQLite driver, which makes it return a result before the actual commit.

When using fetch_one() for queries with a RETURNING clause, the query prematurely returns after fetching the first result row without ensuring the SQLite statement is fully completed.

This bug was causing the test test_sqlite_repository_read_only() to fail sometimes when creating a database at

let id = sqlx::query(r#"INSERT INTO database (name) VALUES ($1) RETURNING (id)"#)
.bind(database_name)
.

In this PR, I implement a workaround by manually starting a transaction before running the query and committing it afterwards.

Flaky failure example:

https://github.com/splitgraph/seafowl/actions/runs/10721496337/job/29730146388

@lizardoluis lizardoluis self-assigned this Sep 6, 2024
@lizardoluis lizardoluis force-pushed the flaky_test_sqlite_repository_read_only branch from 8a47781 to a33b33d Compare September 6, 2024 09:13
@lizardoluis lizardoluis requested review from mildbyte and gruuya and removed request for mildbyte September 6, 2024 09:14
@lizardoluis lizardoluis changed the title Implement workaround for SQLite driver bug returning a result before the commit. Fix flaky. Workaround for SQLite driver bug returning a result before the commit. Sep 6, 2024
Copy link
Contributor

@gruuya gruuya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great find!

For the sake of simplicity my only recommendation would be to use the tx only for DML using the RETURNING clause (the potentially buggy ones), and leave the rest of the queries as before (the pure read ones such as get_database).

@lizardoluis
Copy link
Collaborator Author

Ok, I removed the tx from the others

@lizardoluis lizardoluis merged commit 80c3bbf into main Sep 6, 2024
2 checks passed
@lizardoluis lizardoluis deleted the flaky_test_sqlite_repository_read_only branch September 6, 2024 09:54
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

Successfully merging this pull request may close these issues.

2 participants