BUG: daily_activity_logs insert loop has no deduplication re-saving an activity creates duplicate logs
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 55/100
Research direction
Start in therapist/lib/repository/supabase_therapy_repository.dart around line 316 and inspect the database definition for daily_activity_logs. Confirm the save path handles an existing activity/date/patient combination without creating duplicates, and that the database enforces the stated uniqueness constraint.
Written by the indexing model from the issue text.
Description
Is there an existing issue for this?
- I have searched the existing issues
What happened?
📌 Issue Overview
The insert loop in supabase_therapy_repository.dart unconditionally
inserts a new row into daily_activity_logs for every date in the
activity's date range with no check for existing records. Re-saving or
editing a daily activity creates duplicate logs for the same
activity_id + date + patient_id combination.
This is the root cause of the PGRST116 crash fixed in #167 — duplicate
logs for the same day cause .maybeSingle() to throw "Results contain
more than one row".
🔍 Steps to Reproduce
- Therapist creates a daily activity for a patient for dates 1–7
- Therapist edits and re-saves the same activity
daily_activity_logsnow has 2 rows per date for the same activity- Patient opens the Tasks screen → PGRST116 crash or wrong data shown
🎯 Expected Behavior
Re-saving a daily activity should update existing logs rather than
inserting duplicates. Each activity_id + date + patient_id
combination should have at most one log.
🚨 Actual Behavior
Every save unconditionally inserts new rows, creating duplicates.
therapist/lib/repository/supabase_therapy_repository.dart, line 316:
await _supabaseClient.from('daily_activity_logs').insert({
'activity_id': dailyActivity.id,
'date': date.toString(),
'activity_items': dailyActivity.activityList,
'patient_id': dailyActivity.patientId,
}); // no deduplication — inserts duplicate rows on re-save
📷 Screenshot
N/A
💡 Suggested Improvements
Replace .insert() with .upsert() using onConflict on
activity_id + date + patient_id:
await _supabaseClient.from('daily_activity_logs').upsert({
'activity_id': dailyActivity.id,
'date': date.toString(),
'activity_items': dailyActivity.activityList,
'patient_id': dailyActivity.patientId,
}, onConflict: 'activity_id, date, patient_id'); // upsert prevents duplicates
Additionally, add a unique constraint at the DB level:
ALTER TABLE daily_activity_logs
ADD CONSTRAINT uq_activity_date_patient
UNIQUE (activity_id, date, patient_id);
Record
- I agree to follow this project's Code of Conduct
- I want to work on this issue
- Dominant language
- Dart
- Stars
- 30
- Forks
- 49
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from AOSSIE-Org/NeuroTrack
-
fix(therapist): Method marked @override does not override any inherited methodPossibly taken @Muneerali199 claimed this 259 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
AOSSIE-Org/NeuroTrack#198 ·
-
fix: Don't use BuildContext across async gaps (use_build_context_synchronously)Possibly taken @Muneerali199 claimed this 259 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
AOSSIE-Org/NeuroTrack#197 ·
-
fix(patient): Remove unused and duplicate imports across patient appPossibly taken @Muneerali199 claimed this 259 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
AOSSIE-Org/NeuroTrack#195 ·
-
BUG: Therapy details save button has no loading guard, allowing duplicate submissions that inflate patient regression reportsPossibly taken @Varadraj75 claimed this 222 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 68/100
AOSSIE-Org/NeuroTrack#221 ·
-
BUG: Appointment booking ignores selected time slot, every appointment saved at midnight to SupabasePossibly taken @Varadraj75 claimed this 227 days ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 55/100
AOSSIE-Org/NeuroTrack#219 ·
All issues in AOSSIE-Org/NeuroTrack
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Anxcye/anx-reader#1024 ·
-
[cloud_functions]: Apple platforms ignore custom domains passed as regionPossibly taken @ragavendranbala-TSL claimed this today. OpenNeeds Attention platform: ios platform: macos plugin: functions type: bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
firebase/flutterfire#19015 · 2 comments ·
Maintainers usually reply within 4 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
RevenueCat/purchases-flutter#2048 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
hajisensai/Fushi#4543 · 3 comments ·
Maintainers usually reply within 1 day
-
[video_player] _updatePosition sets isCompleted=true after 500ms when duration is Duration.zeroOpen
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day