Skip to content

refactor: enforce non-null constraints on consume_coupon fields#1805

Draft
purplesmoke05 wants to merge 1 commit intodev-26.6from
refactor/#1793
Draft

refactor: enforce non-null constraints on consume_coupon fields#1805
purplesmoke05 wants to merge 1 commit intodev-26.6from
refactor/#1793

Conversation

@purplesmoke05
Copy link
Copy Markdown
Member

📌 Description

Refactor indexed position aggregation to enforce token-type-specific query invariants in SQL, remove defensive assertions and broad tuple casts, and harden coupon consumption nullability.

✅ Related Issues

🔄 Changes

  • Refactored /Position/{account_address} indexed aggregation to build token-type-specific queries and merge them with UNION ALL.
  • Moved pagination and ordering for aggregated positions back to SQL to preserve existing behavior and avoid Python-side full-result pagination.
  • Replaced broad result typing workarounds with Nullable(...) and type_coerce(...) where SQLAlchemy result typing needed explicit nullability/type hints.
  • Removed defensive assert usage in aggregated position handling by making token cache presence guaranteed by the query shape.
  • Enforced NOT NULL for consume_coupon.amount and consume_coupon.block_timestamp via migration and updated ORM typing accordingly.
  • Simplified coupon consumption response handling to treat amount and block_timestamp as non-null.
  • Added regression tests for missing token cache rows in aggregated position results.
  • Added migration tests for cleanup of invalid consume_coupon rows and NOT NULL enforcement.

📌 Checklist

  • I have added tests where necessary.
  • I have updated the documentation where necessary.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 3, 2026

Coverage

Coverage Report •
FileStmtsMissBranchBrPartCoverMissing
app/api/routers
   position.py460961502779%479, 486, 533–534, 558–563, 621–622, 649–650, 684–689, 729–730, 757–758, 792–797, 1069–1070, 1097–1098, 1141–1146, 1217–1228, 1230–1231, 1241, 1279–1290, 1292–1293, 1303, 1339–1340, 1384–1393, 1395–1396, 1405, 1441, 1478, 1513, 1542, 1605–1607, 1615, 1622, 1894, 1903
app/model/db
   idx_consume_coupon.py12000100% 
tests/app
   position_PositionCoupon_test.py40928299%190, 197
   position_Position_test.py460224299%73, 82
TOTAL378741704369275995% 

Tests Skipped Failures Errors Time
1269 0 💤 0 ❌ 0 🔥 10m 18s ⏱️

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.

[REFACTOR] Remove defensive asserts from position aggregation queries

1 participant