Skip to content

fix(tests): store UUID ids as text on the SQLite test engines - #59

Merged
widrss merged 1 commit into
mainfrom
fix/flaky-repo-visibility-test
Nov 18, 2026
Merged

widrss merged 1 commit into
mainfrom
fix/flaky-repo-visibility-test

Conversation

@widrss

@widrss widrss commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

The flake

The backend suite failed at random on main and passed on re-run with no code change:

AttributeError: 'float' object has no attribute 'replace'
.../uuid.py:175

It hit a different test each time: test_github_visibility.py::test_backfill_github_failure_prints_no_token in run 43744560230, and the setup of test_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.

  • The models declare ids as sqlalchemy.dialects.postgresql.UUID(as_uuid=True).
  • Tests create those tables on in-memory SQLite. SQLite has no UUID type, so SQLAlchemy emits the name UUID as is, and SQLite gives a column declared that way NUMERIC affinity.
  • SQLAlchemy binds a UUID on SQLite as its 32-character hex string. If that string holds only decimal digits, or digits around a single e, SQLite treats it as a number and stores an integer or a real.
  • The ORM insert reads the id back (INSERT ... RETURNING) and passes it to uuid.UUID(), which gets a float. The failing run's traceback shows hex = 9.641709507934755e+31.

About 1.4 in a million uuid.uuid4() values have that shape, and the suite calls uuid.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:

sqlite> create table t (id UUID primary key, c CHAR(32));
sqlite> insert into t values ('96417095079347554234823412345678', '96417095079347554234823412345678');
sqlite> select id, typeof(id), typeof(c) from t;
9.641709507934755e+31|real|text

Fix

backend/tests/conftest.py (new) compiles the UUID type to CHAR(32) on SQLite. That is what SQLAlchemy's portable Uuid type emits there; it has TEXT affinity, so every id is stored as the string that was bound. PostgreSQL still gets native UUID.

backend/tests/test_sqlite_uuid_storage.py (new) is the deterministic reproduction: it inserts valid v4 ids that look like numbers (all digits, digits around e, 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 main failed for a different reason: test_github_my_leases.py::test_serialized_response_keys_omit_secrets asserted "9999" not in response.text, and the response also holds random bounty ids. About one random UUID in 2,000 contains 9999 (that run drew ...-229999ea6175). The test now checks the parsed values for the 9999 amount instead.

Evidence

  • With uuid.uuid4 forced 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).
  • With uuid.uuid4 forced to return ids containing 9999, test_serialized_response_keys_omit_secrets fails before and passes after.
  • With uuid.uuid4 forced to return all-digit v4 ids for the whole suite: 477 failed and 190 errors before this change, 2139 passed after.
  • Full suite run 20 times in a row locally with the change: 20 of 20 runs, 2139 passed each.

No retry, rerun plugin, skip or xfail was added.

🤖 Generated with Claude Code

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>
@widrss
widrss merged commit c192a7f into main Nov 18, 2026
3 checks passed
@widrss
widrss deleted the fix/flaky-repo-visibility-test branch November 18, 2026 03:42
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.

1 participant