Repository navigation
fix(tests): store UUID ids as text on the SQLite test engines - #59
Merged
Merged
Conversation
The backend suite failed at random, about once in 25 CI runs, with
AttributeError: 'float' object has no attribute 'replace'
raised from uuid.UUID() during a flush, in a different test each time.
The models declare ids with the PostgreSQL UUID type. On the in-memory
SQLite engines the tests use, SQLAlchemy emits the type name "UUID" as is,
and SQLite gives a column declared that way NUMERIC affinity. A UUID is
bound as its 32-character hex string, so an id whose hex holds only decimal
digits, or digits around one "e", is stored as an integer or a real. About
one uuid.uuid4() in a million has that shape. SQLAlchemy then reads the id
back from the INSERT ... RETURNING and passes the float to uuid.UUID().
tests/conftest.py now compiles the type to CHAR(32) on SQLite, which is what
SQLAlchemy's portable Uuid type emits there. It has TEXT affinity, so every
id is stored as bound. PostgreSQL still gets its native UUID type; no
application code changes, and production was never affected.
Also fix a second random failure seen on main (run 44224479652):
test_serialized_response_keys_omit_secrets asserted that "9999" does not
appear anywhere in the response text, which also holds random bounty ids.
It now compares the parsed values.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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.
The flake
The backend suite failed at random on
mainand passed on re-run with no code change:It hit a different test each time:
test_github_visibility.py::test_backfill_github_failure_prints_no_tokenin run 43744560230, and the setup oftest_repo_visibility.py::test_submission_list_404_unless_can_view[submitted-open-solver-200]in the first attempt of run 44227566278.Cause
This is a test-environment problem. Production (PostgreSQL) is not affected and no application code changes.
sqlalchemy.dialects.postgresql.UUID(as_uuid=True).UUIDas is, and SQLite gives a column declared that way NUMERIC affinity.e, SQLite treats it as a number and stores an integer or a real.INSERT ... RETURNING) and passes it touuid.UUID(), which gets a float. The failing run's traceback showshex = 9.641709507934755e+31.About 1.4 in a million
uuid.uuid4()values have that shape, and the suite callsuuid.uuid4()about 15,000 times per run, so the expected rate is on the order of one run in 50 to 100. It was seen in 2 of the last 52 CI attempts. The failure is random and independent of test order. Three test files already avoid it locally by putting a hex letter in their fixed ids (test_github_my_leases.py,test_fix_verifications_routes.py,test_verifier_bypass.py).SQLite alone shows it:
Fix
backend/tests/conftest.py(new) compiles theUUIDtype toCHAR(32)on SQLite. That is what SQLAlchemy's portableUuidtype emits there; it has TEXT affinity, so every id is stored as the string that was bound. PostgreSQL still gets nativeUUID.backend/tests/test_sqlite_uuid_storage.py(new) is the deterministic reproduction: it inserts valid v4 ids that look like numbers (all digits, digits arounde, small integer), through Core and through an ORM flush of a real model, and checks the DDL on both dialects. All 7 tests fail without the conftest and pass with it.Second flake, same PR
Run 44224479652 on
mainfailed for a different reason:test_github_my_leases.py::test_serialized_response_keys_omit_secretsasserted"9999" not in response.text, and the response also holds random bounty ids. About one random UUID in 2,000 contains9999(that run drew...-229999ea6175). The test now checks the parsed values for the 9999 amount instead.Evidence
uuid.uuid4forced to return all-digit v4 ids, the test named in the CI failure errors at setup with the same traceback before this change (22 of 22 selected tests fail or error) and passes after (22 passed).uuid.uuid4forced to return ids containing9999,test_serialized_response_keys_omit_secretsfails before and passes after.uuid.uuid4forced to return all-digit v4 ids for the whole suite: 477 failed and 190 errors before this change, 2139 passed after.No retry, rerun plugin, skip or xfail was added.
🤖 Generated with Claude Code