fix(phase-03): use UUID.hex in raw SQL to fix SQLite UUID format mismatch
str(uuid_obj) produces dashed 36-char format; SQLite stores UUID as 32-char hex without dashes, so WHERE user_id = :uid never matched. Using .hex fixes confirm_upload (api/documents.py) and delete_document (services/storage.py). Removes stale xfail from test_delete_decrements_quota — now passes on SQLite. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -346,7 +346,7 @@ async def confirm_upload(
|
|||||||
" AND (used_bytes + :delta) <= limit_bytes "
|
" AND (used_bytes + :delta) <= limit_bytes "
|
||||||
"RETURNING used_bytes, limit_bytes"
|
"RETURNING used_bytes, limit_bytes"
|
||||||
),
|
),
|
||||||
{"delta": size, "uid": str(doc.user_id)},
|
{"delta": size, "uid": doc.user_id.hex},
|
||||||
)
|
)
|
||||||
row = result.fetchone()
|
row = result.fetchone()
|
||||||
|
|
||||||
@@ -354,7 +354,7 @@ async def confirm_upload(
|
|||||||
# Quota exceeded — fetch current quota state for the 413 body
|
# Quota exceeded — fetch current quota state for the 413 body
|
||||||
quota_result = await session.execute(
|
quota_result = await session.execute(
|
||||||
text("SELECT used_bytes, limit_bytes FROM quotas WHERE user_id = :uid"),
|
text("SELECT used_bytes, limit_bytes FROM quotas WHERE user_id = :uid"),
|
||||||
{"uid": str(doc.user_id)},
|
{"uid": doc.user_id.hex},
|
||||||
)
|
)
|
||||||
q = quota_result.fetchone()
|
q = quota_result.fetchone()
|
||||||
# Delete the pending Document row and best-effort remove the MinIO object
|
# Delete the pending Document row and best-effort remove the MinIO object
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ async def delete_document(
|
|||||||
"SET used_bytes = CASE WHEN used_bytes > :delta THEN used_bytes - :delta ELSE 0 END "
|
"SET used_bytes = CASE WHEN used_bytes > :delta THEN used_bytes - :delta ELSE 0 END "
|
||||||
"WHERE user_id = :uid"
|
"WHERE user_id = :uid"
|
||||||
),
|
),
|
||||||
{"delta": doc.size_bytes, "uid": str(doc.user_id)},
|
{"delta": doc.size_bytes, "uid": doc.user_id.hex},
|
||||||
)
|
)
|
||||||
|
|
||||||
await session.delete(doc)
|
await session.delete(doc)
|
||||||
|
|||||||
@@ -192,7 +192,6 @@ async def test_quota_exceeded_response(
|
|||||||
assert detail["limit_bytes"] == 104_857_600, f"Unexpected limit_bytes: {detail}"
|
assert detail["limit_bytes"] == 104_857_600, f"Unexpected limit_bytes: {detail}"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.xfail(strict=False, reason="requires PostgreSQL for atomic UUID-typed quota SQL")
|
|
||||||
async def test_delete_decrements_quota(
|
async def test_delete_decrements_quota(
|
||||||
async_client, db_session, auth_user, mock_minio_presigned, mock_minio_stat, monkeypatch
|
async_client, db_session, auth_user, mock_minio_presigned, mock_minio_stat, monkeypatch
|
||||||
):
|
):
|
||||||
|
|||||||
Reference in New Issue
Block a user