omi icon indicating copy to clipboard operation
omi copied to clipboard

[Bounty Proposal] Validate inputs and use merge writes in database calendar meetings

Open Ariyachan opened this issue 2 months ago • 1 comments

Problem

  1. NotFound exception in update_meeting (backend/database/calendar_meetings.py:63): update_meeting executes:

    _get_meetings_collection(uid).document(meeting_id).update(meeting_data)
    

    If the target meeting document in users/{uid}/meetings/{meeting_id} does not exist (for example, if purged by retention cleanup, deleted concurrently, or if an out-of-order calendar sync event arrives), Firestore raises google.api_core.exceptions.NotFound: 404 No document to update. This crashes calendar synchronization jobs and endpoints with an unhandled exception.

  2. Unchecked KeyError in create_meeting (backend/database/calendar_meetings.py:46): calendar_meeting_doc_id(uid, meeting_data['calendar_source'], meeting_data['calendar_event_id']) directly indexes 'calendar_source' and 'calendar_event_id', raising an unhandled KeyError if either attribute is omitted.

  3. Unhandled AttributeError on non-datetime in _to_utc (backend/database/calendar_meetings.py:98): _to_utc accesses dt.tzinfo without type validation. If a non-datetime value (such as None or an ISO string) is passed, Python raises AttributeError: 'NoneType'/'str' object has no attribute 'tzinfo'.

  4. Missing parameter validation on meeting_id: update_meeting and delete_meeting do not guard against empty meeting_id strings.

Proposed Solution

  • Switch update_meeting to _get_meetings_collection(uid).document(meeting_id).set(meeting_data, merge=True) for idempotent and resilient updates.
  • Validate required keys in create_meeting, update_meeting, and delete_meeting, raising ValueError on missing identifiers.
  • Validate isinstance(dt, datetime) in _to_utc with explicit TypeError.
  • Add comprehensive regression tests in backend/tests/unit/test_database_calendar_meetings_resilience.py.

Ariyachan avatar Sep 26 '26 02:09 Ariyachan

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! 🙏

undivisible avatar Oct 22 '26 11:10 undivisible