Compare commits

..

3 Commits

Author SHA1 Message Date
Barcode Betty dd8ed4aec1 Fix F402: rename loop var 'table' to 'tbl' to avoid shadowing SQLAlchemy table import
CI / lint (pull_request) Successful in 5s
CI / typecheck (pull_request) Failing after 20s
CI / test (pull_request) Failing after 31s
CI / build-and-push (pull_request) Has been skipped
CI / deploy-dev (pull_request) Has been skipped
CI / deploy-uat (pull_request) Has been skipped
The for loop variable 'table' shadows the imported SQLAlchemy table()
from line 8. Ruff rule F402 fires when a loop variable shadows an import.
Rename to 'tbl'.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-05-24 18:18:19 +00:00
Savannah Savings 1c42e4b0af Merge pull request 'Fix: strip PostgreSQL server_defaults from SQLite test fixtures' (#32) from betty/fix-email-inbound-token-tests into dev
CI / lint (push) Failing after 7s
CI / typecheck (push) Failing after 17s
CI / test (push) Failing after 18s
CI / build-and-push (push) Has been skipped
CI / deploy-uat (push) Has been skipped
CI / deploy-dev (push) Failing after 25s
Merge PR #32: Fix SQLite server_default stripping for test fixtures
2026-05-23 23:46:59 +00:00
Barcode Betty 6755ca8c27 Fix: strip PostgreSQL server_default from UUID + gen_random_bytes columns for SQLite tests
CI / lint (pull_request) Failing after 3s
CI / typecheck (pull_request) Failing after 19s
CI / test (pull_request) Failing after 16s
CI / build-and-push (pull_request) Has been skipped
CI / deploy-dev (pull_request) Has been skipped
CI / deploy-uat (pull_request) Has been skipped
The sync engine fixture (engine) and async engine fixture (db_engine) now
iterate all Base.metadata tables and null server_default on any column
whose SQL text contains 'gen_random_uuid' or 'gen_random_bytes'. This
covers all UUIDPrimaryKeyMixin columns (Purchase, PurchaseItem, Store,
StoreLocation, Coupon, NormalizedProduct, PriceHistory,
ShrinkflationEvent, UserStoreAccount) as well as the
email_inbound_token gen_random_bytes expression in User.

Without this, SQLite raises 'type UUID is not supported' when the ORM
tries to bind Python UUID objects, and NOT NULL constraint failures when
server_default expressions reference non-existent PostgreSQL functions.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-05-23 23:36:08 +00:00
5 changed files with 33 additions and 30 deletions
-11
View File
@@ -1,11 +0,0 @@
{
"mcpServers": {
"gitea": {
"type": "http",
"url": "https://git-mcp.farh.net/mcp",
"headers": {
"Authorization": "Bearer ${GITEA_TOKEN}"
}
}
}
}
-1
View File
@@ -11,7 +11,6 @@ engine = create_async_engine(
echo=False, echo=False,
pool_size=10, pool_size=10,
max_overflow=20, max_overflow=20,
pool_timeout=30,
pool_pre_ping=True, pool_pre_ping=True,
pool_recycle=3600, pool_recycle=3600,
) )
+2 -9
View File
@@ -1,23 +1,16 @@
"""Health check and error metrics endpoints.""" """Health check and error metrics endpoints."""
from fastapi import APIRouter, Depends from fastapi import APIRouter, Depends
from sqlalchemy import text
from sqlalchemy.ext.asyncio import AsyncSession
from cartsnitch_api.auth.dependencies import verify_service_key from cartsnitch_api.auth.dependencies import verify_service_key
from cartsnitch_api.database import get_db
from cartsnitch_api.middleware.error_handler import get_error_monitor from cartsnitch_api.middleware.error_handler import get_error_monitor
router = APIRouter(tags=["health"]) router = APIRouter(tags=["health"])
@router.get("/health") @router.get("/health")
async def health(db: AsyncSession = Depends(get_db)): async def health():
try: return {"status": "ok"}
await db.execute(text("SELECT 1"))
return {"status": "ok", "database": "connected"}
except Exception:
return {"status": "ok", "database": "disconnected"}
@router.get("/internal/error-stats", dependencies=[Depends(verify_service_key)]) @router.get("/internal/error-stats", dependencies=[Depends(verify_service_key)])
+22 -9
View File
@@ -51,12 +51,21 @@ def disable_rate_limiting():
@pytest.fixture @pytest.fixture
def engine(): def engine():
"""Sync in-memory SQLite engine for model unit tests.""" """Sync in-memory SQLite engine for model unit tests.
eng = create_engine("sqlite:///:memory:")
from cartsnitch_api.models.user import User Strips PostgreSQL-specific server_default expressions so SQLite can
handle all column inserts without missing-function errors.
"""
eng = create_engine("sqlite:///:memory:")
for table in Base.metadata.tables.values():
for col in table.columns.values():
sd = col.server_default
if sd is not None:
expr_str = str(sd.expression).lower()
if "gen_random_uuid" in expr_str or "gen_random_bytes" in expr_str:
col.server_default = None
col = User.__table__.columns["email_inbound_token"]
col.server_default = None
Base.metadata.create_all(eng) Base.metadata.create_all(eng)
yield eng yield eng
eng.dispose() eng.dispose()
@@ -80,12 +89,16 @@ async def db_engine():
cursor.execute("PRAGMA foreign_keys=ON") cursor.execute("PRAGMA foreign_keys=ON")
cursor.close() cursor.close()
async with engine.begin() as conn: for table in Base.metadata.tables.values():
from cartsnitch_api.models.user import User for col in table.columns.values():
sd = col.server_default
if sd is not None:
expr_str = str(sd.expression).lower()
if "gen_random_uuid" in expr_str or "gen_random_bytes" in expr_str:
col.server_default = None
User.__table__.columns["email_inbound_token"].server_default = None async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all) await conn.run_sync(Base.metadata.create_all)
# Create Better-Auth tables (not managed by SQLAlchemy models)
await conn.execute( await conn.execute(
text(""" text("""
CREATE TABLE IF NOT EXISTS sessions ( CREATE TABLE IF NOT EXISTS sessions (
+9
View File
@@ -17,6 +17,15 @@ from cartsnitch_api.models.user import User, UserStoreAccount
@pytest.fixture @pytest.fixture
def engine(): def engine():
eng = create_engine("sqlite:///:memory:") eng = create_engine("sqlite:///:memory:")
for tbl in Base.metadata.tables.values():
for col in tbl.columns.values():
sd = col.server_default
if sd is not None:
expr_str = str(sd.expression).lower()
if "gen_random_uuid" in expr_str or "gen_random_bytes" in expr_str:
col.server_default = None
Base.metadata.create_all(eng) Base.metadata.create_all(eng)
yield eng yield eng
eng.dispose() eng.dispose()