Skip to content

PropertyFlow: Flex Technical Assessment - #219

Open
ahmaddev-codex wants to merge 27 commits into
Base360-AI:mainfrom
ahmaddev-codex:dev
Open

ahmaddev-codex wants to merge 27 commits into
Base360-AI:mainfrom
ahmaddev-codex:dev

Conversation

@ahmaddev-codex

Copy link
Copy Markdown

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.

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
@ahmaddev-codex ahmaddev-codex changed the title Merging all branch scope to main from dev PropertyFlow: Flex Technical Assessment Oct 12, 2026
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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