omi
omi copied to clipboard
[Bounty Proposal] Fix explicit None defaults and missing-doc crashes in user settings
Problem
- Explicit
Nonesettings default to disabled instead of enabled (backend/database/users.py:236-260):get_meeting_note_screenshots_enabledandget_user_private_cloud_sync_enabledpreviously useduser_data.get(..., True). When an explicitNonevalue is stored on a user document in Firestore (for example after a migration or partial settings update),dict.get(..., True)returnsNone. Consequently, callers evaluatingif get_meeting_note_screenshots_enabled(uid):orif get_user_private_cloud_sync_enabled(uid):treat the returnedNoneasFalse, incorrectly disabling features whose documented contract specifies defaultTrue. Noneserialization failure inget_notification_settings(backend/database/users.py:2253-2256): Whenusers/{uid}has'notifications_enabled': Noneor'notification_frequency': None,get_notification_settingsreturned{'enabled': None, 'frequency': None}. The Swift client'sNotificationSettingsResponserequires non-optionalBoolandIntfields, causing JSON decoding errors. Furthermore, ifdoc.to_dict()returnedNone(on empty document snapshots),data.get(...)raised unhandledAttributeError.- Unhandled
AttributeErroron empty document snapshots across settings and profile getters: In_get_raw_assistant_settings,get_assistant_settings,get_user_speaker_embedding, and_get_ai_user_profile_from_firestore, callingdoc.to_dict().get(...)raisedAttributeError: 'NoneType' object has no attribute 'get'whenever an existing document snapshot returnedNonefor.to_dict(). NotFoundexceptions on uninitialized user documents:set_user_store_recording_permission,set_meeting_note_screenshots_enabled, andset_user_private_cloud_sync_enabledused.update(...), raisinggoogle.api_core.exceptions.NotFoundwhen invoked for a user whose document has not yet been initialized in Firestore.
Proposed Solution
- In
get_meeting_note_screenshots_enabledandget_user_private_cloud_sync_enabled, returnTruewhen stored field value isNone, while preserving explicitFalse. - In
get_notification_settings, defaultenabledtoTrueandfrequencyto0when fields areNone, and guarddoc.to_dict()withor {}. - Guard
doc.to_dict()withor {}across settings and profile getters. - Use
.set(..., merge=True)in user settings update methods. - Add unit tests in
backend/tests/unit/test_users_settings_null_defaults.py.
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! 🙏