Repository navigation
PropertyFlow: Flex Technical Assessment - #219
Open
ahmaddev-codex wants to merge 27 commits into
Open
ahmaddev-codex wants to merge 27 commits into
ahmaddev-codex wants to merge 27 commits into
Conversation
The pool read settings that don't exist, used a sync-only pool class, and was missing greenlet, so it never connected.
Query failures returned hardcoded totals that looked real. Reuse the shared pool and return 503 when the database is unavailable.
Property IDs repeat across tenants, so a shared key served one tenant's cached revenue to another.
Keeps uv config in sync with requirements.txt.
Totals were cast to float, which drifts on sub-cent amounts. Round once with ROUND_HALF_UP and return the amount as a string.
Math.round on floats rounds half-cents down (1.005 -> 1.00). Use the backend-rounded value and drop the float-based mismatch warning.
dist is generated by npm run build inside the Docker image.
Month boundaries were naive UTC, so a booking at 23:30 UTC on Feb 29 (00:30 Mar 1 in Paris) was counted in February. The stub also returned 0 and ignored tenant_id.
Monthly results are cached per tenant, property and month.
Empty shows all-time revenue; a selected month uses the property-local monthly total.
Unknown users fell back to tenant-a and the dashboard to a "default_tenant". Both now resolve to no tenant and get a 403.
The property dropdown was hardcoded with every tenant's properties, and labelled Ocean's prop-001 with Sunset's name. Load it from the API and drop the unused X-Simulated-Tenant header.
chore: add gitignore, untrack build output and .env
fix(cache): scope revenue cache key by tenant
fix(revenue): connect to database and remove mock fallback
fix(revenue): round totals to cents with Decimal
fix(revenue): use property time zone for monthly totals
feat(dashboard): add month picker to revenue overview
fix(tenant): scope properties to the signed-in tenant
Comment on lines
+91
to
+93
| # Unknown users get no tenant rather than another company's data. | ||
| logger.warning(f"No tenant mapping for {user_email}") | ||
| return None |
There was a problem hiding this comment.
Bug: The new tenant resolver only works for test emails, causing the auth cache to be invalidated on every request for real users, forcing a re-authentication loop.
Severity: CRITICAL
Suggested Fix
Update tenant_resolver.py to correctly resolve tenant IDs for all production users, not just the hardcoded test emails. This likely involves restoring the previous logic or implementing a proper lookup based on the user's email or other attributes from the database.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: backend/app/core/tenant_resolver.py#L91-L93
Potential issue: The tenant resolution logic in `tenant_resolver.py` was changed to only
return a `tenant_id` for three hardcoded test emails, returning `None` for all other
users. In `auth.py`, the authentication caching logic explicitly checks `if not
cached_user.tenant_id` on a cache hit. If `tenant_id` is `None`, it deletes the cache
entry and forces a full re-authentication. This interaction creates a perpetual
re-authentication loop for every real production user on every API request, completely
bypassing the 30-minute auth cache and placing excessive load on the Supabase
authentication service.
Did we get this right? 👍 / 👎 to inform future reviews.
fix(tenant): resolve tenant from token claims
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
All feature branched were merged with a PR to dev for development approval with the product (assignment) expectations. Now dev is merged to main after a second review.