omi
omi copied to clipboard
[Bounty Proposal] Validate inputs, handle exceptions, and use merge writes in database wrapped
Problem
-
Uncaught exceptions on invalid or empty parameters (
backend/database/wrapped.py:47-91):get_wrapped(uid, year),create_wrapped(uid, year),reset_wrapped_for_regeneration(uid, year),update_wrapped_status(...), andupdate_wrapped_progress(...)operate directly ondb.collection('users').document(uid).collection('wrapped').document(str(year)).- Passing an empty or whitespace
uidraisesValueError: A document id must not be emptyinside Firestore. - Non-positive or non-integer
yeararguments create unintended subcollections or malformed document paths.
-
Destructive overwrites on creation and reset (
backend/database/wrapped.py:91, 193):create_wrappedandreset_wrapped_for_regenerationinvokewrapped_ref.set(wrapped_data)withoutmerge=True.- Any auxiliary metadata, client flags, or custom fields previously attached to the document are wiped out.
-
Check-then-act race and uncaught
NotFoundexceptions (backend/database/wrapped.py:119-136, 155-163):update_wrapped_statusandupdate_wrapped_progressperform a two-stepget()thenupdate(...).- If the document is deleted or expires concurrently between
.get()and.update(), Firestore raises an unhandledgoogle.api_core.exceptions.NotFound, crashing background worker processes. is_wrapped_stuckdoes not verify thatwrapped_datais a valid dictionary before accessing keys.
Proposed Solution
- Add input validation for
uid(non-empty string) andyear(positive integer) across all database wrapped methods. - Switch
wrapped_ref.set(wrapped_data)increate_wrappedandreset_wrapped_for_regenerationtowrapped_ref.set(wrapped_data, merge=True)for non-destructive persistence. - Wrap
wrapped_ref.update(...)calls intry...exceptto catchNotFoundor transient exceptions on concurrent deletion, returningFalsecleanly. - Add defensive type validation to
is_wrapped_stuck. - Provide full regression and resilience coverage with unit tests in
backend/tests/unit/test_database_wrapped_resilience.py.
🚀 Bounty Fix Submitted
I have completed the fix for this issue in Pull Request: PR #19121
- Full implementation, tested, zero regressions.
- Ready for review and merge.
💸 Contributor Bounty Payout Coordinates:
- UPI (Instant INR):
9227095624@kotak811 - PayPal (USD/Global): https://paypal.me/hardikkakkad
- Kotak Bank A/C:
6845336786(IFSC:KKBK0002936)
Thanks for putting this together. We aren't doing bounties at the moment, so we're closing the bounty proposal issues for now — thanks for the fix! 🙏