Skip to content

Task/correct bugs on assessment - #231

Open
Chukky9 wants to merge 7 commits into
Base360-AI:mainfrom
Chukky9:task/correct-bugs-on-assessment
Open

Chukky9 wants to merge 7 commits into
Base360-AI:mainfrom
Chukky9:task/correct-bugs-on-assessment

Conversation

@Chukky9

@Chukky9 Chukky9 commented Oct 29, 2026 •

Copy link
Copy Markdown

Summary

  • March revenue for Sunset's Beach House was short because check-ins were bucketed in UTC. A 29 February 23:30 UTC arrival is 1 March in Europe/Paris, so that booking now counts in March. The March 2024 total for Beach House Alpha is USD 2,250.00.
  • Ocean Rentals could see Sunset's figures for prop-001 because the Redis key was only the property id, and both companies use that id. Cache keys now include the tenant, and each dashboard only lists that tenant's properties.
  • Totals were off by cents because three-decimal booking amounts were cast through binary floats and rounded per line. The sum is kept as a decimal and rounded to cents once, then returned as a string.
  • The database pool was pointed at DATABASE_URL. It had been using unset Supabase settings and falling back to the same mock totals for every client.

Test plan

  • cd backend && PYTHONPATH=. python3 tests/test_revenue_rules.py
  • docker compose down -v && docker compose up --build
  • Sign in as sunset@propertyflow.com / client_a_2024. Confirm only Sunset properties are listed, and Beach House Alpha shows USD 2,250.00 for March 2024 in Europe/Paris with 4 bookings.
  • Sign in as ocean@propertyflow.com / client_b_2024. Confirm Mountain Lodge Beta shows USD 0.00, and Lakeside Cottage and Urban Loft Modern are the only other properties.
  • Refresh both sessions and confirm the numbers do not swap.
  • Request the other company's property id and confirm the API returns 404.

…Supabase URL from settings that are not defined, so every request fell through to shared mock totals.
…ruary check-in is March in Paris, and sub-cent bookings are rounded only after the sum.
…, and a property-only cache key was serving one client's totals to the other.
…properties now 404, and totals stay as cent strings instead of binary floats.
…nger lists the other company's properties or sends a simulated tenant header.
Comment on lines 39 to 49
const fetchRevenue = async () => {
setLoading(true);
setError('');
try {
// Use SecureAPI to handle authentication automatically
// We pass the simulatedTenant option which SecureAPI will attach as a header
const response = await SecureAPI.getDashboardSummary(propertyId, {
simulatedTenant: activeTenant,
timestamp: Date.now()
});
const response = await SecureAPI.getDashboardSummary(propertyId, { month, year });
setData(response);
} catch (err) {
setData(null);
setError('Failed to load revenue data');
console.error(err);
} finally {

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 fetch effect in RevenueSummary lacks a cancellation guard, causing out-of-order responses to overwrite current data when switching properties rapidly.
Severity: MEDIUM

Suggested Fix

Add a cleanup function inside the useEffect that toggles a cancelled boolean flag or aborts the request via AbortController, preventing state updates if the effect has re-run or unmounted.

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: frontend/src/components/RevenueSummary.tsx#L38-L49

Potential issue: In `RevenueSummary`, the data fetching effect triggers on changes to
`propertyId`, `month`, and `year` without an `AbortController` or cancellation flag. If
a user quickly switches properties, an earlier slower request can resolve after a
subsequent request. The stale response will unconditionally update `data`, `loading`,
and `error`, causing the summary card to display data for a different property than what
is currently selected.

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.

2 participants