Skip to content

Fix revenue dashboard: tenant isolation, accuracy, and precision bugs#110

Open
CodingwithMeet wants to merge 1 commit into
Base360-AI:mainfrom
CodingwithMeet:main
Open

Fix revenue dashboard: tenant isolation, accuracy, and precision bugs#110
CodingwithMeet wants to merge 1 commit into
Base360-AI:mainfrom
CodingwithMeet:main

Conversation

@CodingwithMeet

Copy link
Copy Markdown

This commit addresses three critical production issues:

  1. Cross-tenant data leak (privacy): Cache key was property-scoped only, allowing clients to see each other's cached revenue on page refresh. Fixed by including tenant_id in cache key: revenue:{tenant_id}:{property_id}

  2. Wrong revenue totals (accuracy): DatabasePool referenced non-existent settings, failing silently and returning mock data instead of real reservations. Fixed by using the actual DATABASE_URL and normalizing it to postgresql+asyncpg:// for async operations.

  3. Cents drift (precision): Money was converted through float() which lost precision on NUMERIC(10,3) amounts. Fixed by using Decimal end-to-end with ROUND_HALF_UP rounding to 2 decimals.

  4. Bonus: Timezone bucketing: Monthly revenue was bucketed in naive UTC instead of the property's local timezone, causing bookings to land in the wrong month. Fixed by building month boundaries with the property's ZoneInfo.

Changes:

  • services/cache.py: Tenant-scoped cache key
  • services/reservations.py: Decimal rounding, real DB connection, timezone-aware month bucketing
  • core/database_pool.py: URL normalization, idempotent init, async pool
  • api/v1/dashboard.py: Decimal rounding before serialization

This commit addresses three critical production issues:

1. **Cross-tenant data leak (privacy)**: Cache key was property-scoped only,
   allowing clients to see each other's cached revenue on page refresh.
   Fixed by including tenant_id in cache key: revenue:{tenant_id}:{property_id}

2. **Wrong revenue totals (accuracy)**: DatabasePool referenced non-existent
   settings, failing silently and returning mock data instead of real
   reservations. Fixed by using the actual DATABASE_URL and normalizing it
   to postgresql+asyncpg:// for async operations.

3. **Cents drift (precision)**: Money was converted through float() which
   lost precision on NUMERIC(10,3) amounts. Fixed by using Decimal
   end-to-end with ROUND_HALF_UP rounding to 2 decimals.

4. **Bonus: Timezone bucketing**: Monthly revenue was bucketed in naive UTC
   instead of the property's local timezone, causing bookings to land in
   the wrong month. Fixed by building month boundaries with the property's
   ZoneInfo.

Changes:
- services/cache.py: Tenant-scoped cache key
- services/reservations.py: Decimal rounding, real DB connection, timezone-aware month bucketing
- core/database_pool.py: URL normalization, idempotent init, async pool
- api/v1/dashboard.py: Decimal rounding before serialization

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
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