user_groups: Use UserGroupMembersDict in initial state data.

On the event side, orjson does the work of converting
UserGroupMembersData to json. But when fetching intial state data,
UserGroupMembersData was being returned which is not
json-serializable. This was causing a mismatch in the `verify_action`
workflow of test_events related to stream group settings where
apply_events resulted in a state with `direct_members` and
`direct_subgroups` as part of an ordinary dict, while fetching initial
state data was giving us a UserGroupMembersData class.
This commit uses UserGroupMembersDict where appropriate. It will
still be good to keep around the dataclass class since it has the added
benefit of storing the relevant value when needed.
This commit is contained in:
Shubham Padia
2025-03-11 19:10:37 +00:00
committed by Tim Abbott
parent 37d91d9759
commit b3862c5008
12 changed files with 179 additions and 128 deletions

View File

@@ -115,7 +115,7 @@ from zerver.lib.event_types import (
PlanTypeData,
)
from zerver.lib.topic import ORIG_TOPIC, TOPIC_NAME
from zerver.lib.types import UserGroupMembersData
from zerver.lib.types import UserGroupMembersDict
from zerver.models import Realm, RealmUserDefault, Stream, UserProfile
@@ -549,7 +549,13 @@ def check_stream_update(
assert value in Stream.STREAM_POST_POLICY_TYPES
elif prop in Stream.stream_permission_group_settings:
assert extra_keys == set()
assert isinstance(value, int | UserGroupMembersData)
assert isinstance(value, int | dict)
# We cannot validate a TypedDict using isinstance, thus
# requiring this check.
if isinstance(value, dict):
expected_keys = set(inspect.get_annotations(UserGroupMembersDict).keys())
keys = set(value.keys())
assert expected_keys == keys
elif prop == "first_message_id":
assert extra_keys == set()
assert isinstance(value, int)