Fix: strip PostgreSQL server_defaults from SQLite test fixtures #32
Reference in New Issue
Block a user
Delete Branch "betty/fix-email-inbound-token-tests"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Fixes CAR-1012: 77 test failures + 55 errors caused by PostgreSQL-specific server_default expressions being incompatible with SQLite in-memory test DB.
Changes
tests/conftest.py (both engine and db_engine fixtures):
tests/test_encrypted_json.py:
Why
SQLite cannot evaluate PostgreSQL gen_random_uuid() or complex encode(gen_random_bytes(...)) expressions. Additionally, Python UUID objects cannot be bound as parameters to SQLite without conversion. Stripping these server defaults lets SQLite use Python-side defaults (the ORM default= callable on mapped_column).
Testing
cc @cpfarhood
Good approach — stripping
gen_random_uuid/gen_random_bytesserver_defaults is correct since the Python-sidedefault=uuid.uuid4(in UUIDPrimaryKeyMixin) anddefault=lambda: secrets.token_urlsafe(16)(in User.email_inbound_token) will take over.However, this PR alone won't fix all test failures:
User.idhas no default —Userdoesn't useUUIDPrimaryKeyMixin; it hasid: Mapped[str] = mapped_column(Text, primary_key=True)with nodefaultand noserver_default. Tests creatingUser(...)via ORM without providingidwill still fail withNOT NULL constraint failed: users.id.Affected files (at minimum):
tests/test_encrypted_json.py—userfixture createsUser(email=..., hashed_password=...)withoutidtests/test_routes/test_purchases.py— creates users withoutidFix: provide
id=str(uuid.uuid4())in each ORM user creation, or add adefaultto the User model.UUID type binding —
test_e2e/test_purchase_flow.pyhastype 'UUID' is not supportederrors. SQLite doesn't natively handle Pythonuuid.UUIDobjects. The Purchase model may need a TypeDecorator or the test needs to convert UUIDs to strings.Merge this as-is (it's progress), then follow up with a second PR addressing points 1 and 2 above.
QA FAIL — CI checks still failing on PR #32.
Three failures:
QA FAIL — Requesting changes. Three CI checks failing: (1) lint E501 long lines in alembic files, (2) pre-existing typecheck error in config.py:89, (3) test fixture AttributeError on DefaultClause.expression — add hasattr check. See issue comment for details.