fix: prevent PGRST116 crash in getTodayActivities by adding limit(1) before maybeSingle#168
Conversation
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughA query modification in Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~4 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Fixes getTodayActivities to avoid Supabase/PostgREST PGRST116 (“Results contain more than one row”) when duplicate daily_activity_logs exist for the same patient/day, by ensuring the query returns at most one row.
Changes:
- Add deterministic selection logic to the
daily_activity_logsquery by sorting and limiting before calling.maybeSingle().
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Closes #167
📝 Description
getTodayActivitieswas calling.maybeSingle()directly after a daterange filter on
daily_activity_logs. If more than one log existed forthe same patient on the same day, Supabase would throw a
PGRST116error("Results contain more than one row"), causing the tasks page to silently
show "No activities found".
🔧 Changes Made
patient/lib/repository/supabase_patient_repository.dart: Added.order('date', ascending: false)and.limit(1)before.maybeSingle()to ensure at most one row is returned, always picking the most recent log.
📷 Screenshots or Visual Changes (if applicable)
N/A — error only occurs when duplicate logs exist in the DB.
🤝 Collaboration
Collaborated with: N/A
✅ Checklist
Summary by CodeRabbit