Fix broken 3.8 SQLite test pipeline #266
Merged
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.
Problem
The test
tests/taxii2/test_taxii2_sqldb.py::test_delete_object[wrong collection]
returnssqlite3.OperationalError: disk I/O error
with the envpy38-sqlalchemy14-werkzeuglt21-sqlite
.How to reproduce
Run all the tests with
tox -e py38-sqlalchemy14-werkzeuglt21-sqlite
on a fresh python environment. Delete the old environment if existing before.Other failed attempts to reproduce it, eg it passed:
tox -e py38-sqlalchemy14-werkzeuglt21-sqlite -- tests/test_* <failed-test>
andtox -e py38-sqlalchemy14-werkzeuglt21-sqlite -- tests/taxii2/test_taxii2_sqldb.py
. Both succeeded.tox -e py38-sqlalchemy14-werkzeuglt21-sqlite -- --no-cov
Another surprising fact is that using the
pip freeze
output from last successful run job link also failed locally for me.Hypothesis
A timing issue with sqlite accessing the DB file from a still alive connection while this one is deleted by the fixture
app
(truncate_app
>clean_db
).I am in favor for this hypothesis because, by replacing
os.remove(filename)
withopen(filename, 'w').close()
to just prune the file content. The error is thenOperationalError: database is locked
.According to this SO thread, this is mostly related to leftover connection. It should be added that this error happened more than for just the problematic test so it is not an exact correlation.
Normally SQLite can provide more logs, but the
sqlite3
is not able to leverage it according to this recent discussion. Also SQLite is providing extended error code but those are only available from Python 3.11 where the test always passed.Solution
Explicitly dispose all DB connections from
sqlalchemy
.It is not clear if the closed connection is the fix or just because it delays the code a bit.
Other
Full test report