diff --git a/zerver/lib/compatibility.py b/zerver/lib/compatibility.py index 11f4ec34a9..ddb1fa9f66 100644 --- a/zerver/lib/compatibility.py +++ b/zerver/lib/compatibility.py @@ -140,7 +140,7 @@ def is_unsupported_browser(user_agent: str) -> Tuple[bool, Optional[str]]: return (False, browser_name) -def is_pronouns_field_type_supported(user_agent_str: str) -> bool: +def is_pronouns_field_type_supported(user_agent_str: Optional[str]) -> bool: # In order to avoid users having a bad experience with these # custom profile fields disappearing after applying migration # 0421_migrate_pronouns_custom_profile_fields, we provide this @@ -150,6 +150,9 @@ def is_pronouns_field_type_supported(user_agent_str: str) -> bool: # TODO/compatibility(7.0): Because this is a relatively minor # detail, we can remove this compatibility hack once most users # have upgraded to a sufficiently new mobile client. + if user_agent_str is None: + return True + user_agent = parse_user_agent(user_agent_str) if user_agent["name"] != "ZulipMobile": return True diff --git a/zerver/tests/test_event_system.py b/zerver/tests/test_event_system.py index fbad6864ce..5b1cfbd448 100644 --- a/zerver/tests/test_event_system.py +++ b/zerver/tests/test_event_system.py @@ -50,6 +50,10 @@ from zerver.views.events_register import ( class EventsEndpointTest(ZulipTestCase): + def test_events_register_without_user_agent(self) -> None: + result = self.client_post("/json/register", skip_user_agent=True) + self.assert_json_success(result) + def test_events_register_endpoint(self) -> None: # This test is intended to get minimal coverage on the diff --git a/zerver/views/events_register.py b/zerver/views/events_register.py index 2fdd23dde8..8f3eada336 100644 --- a/zerver/views/events_register.py +++ b/zerver/views/events_register.py @@ -124,7 +124,9 @@ def events_register_backend( client = RequestNotes.get_notes(request).client assert client is not None - pronouns_field_type_supported = is_pronouns_field_type_supported(request.headers["User-Agent"]) + pronouns_field_type_supported = is_pronouns_field_type_supported( + request.headers.get("User-Agent") + ) ret = do_events_register( user_profile, realm,