omi icon indicating copy to clipboard operation
omi copied to clipboard

[Bounty Proposal] Guard staged tasks queries and promotion against empty document snapshots

Open Ariyachan opened this issue 2 months ago • 1 comments

Problem

  1. Unhandled AttributeError during staged task deduplication (backend/database/staged_tasks.py:58): In create_staged_task, deduplication streams existing staged tasks: doc.to_dict().get('description', '') When doc.to_dict() evaluates to None (for an unpopulated or empty Firestore snapshot), calling .get(...) raises AttributeError: 'NoneType' object has no attribute 'get'.

  2. Unhandled TypeError when reading staged tasks (backend/database/staged_tasks.py:92): In get_staged_tasks: data = doc.to_dict() data['id'] = doc.id When doc.to_dict() returns None, item assignment data['id'] raises TypeError: 'NoneType' object does not support item assignment. Other helper functions in this module (get_all_staged_tasks_for_migration, get_active_staged_tasks_for_compatibility) already use doc.to_dict() or {}, making get_staged_tasks inconsistent.

  3. Unhandled TypeError and KeyError during staged task promotion (backend/database/staged_tasks.py:274, 279, 337): In promote_staged_task: staged = docs[0].to_dict() staged['id'] = docs[0].id existing = action_items_db.get_active_action_item_by_description(uid, staged['description']) When docs[0].to_dict() returns None, staged['id'] raises TypeError. Furthermore, accessing staged['description'] directly raises KeyError if the document lacks an explicit description field.

Proposed Solution

  • In create_staged_task, guard data = doc.to_dict() or {} and use data.get('description', '').
  • In get_staged_tasks, guard data = doc.to_dict() or {} before assigning data['id'] = doc.id.
  • In promote_staged_task, guard staged = docs[0].to_dict() or {} and use staged.get('description', '') for deduplication lookup and action item payload creation.
  • Add unit tests in backend/tests/unit/test_staged_tasks_null_guards.py validating that null snapshots and missing fields do not crash deduplication, listing, or promotion.

Ariyachan avatar Sep 25 '26 17: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