import_realm: Fix broken stream group-based settings backfill.

Django seems to have an aggressive check on the type of a field when
setting it through an relation, requiring the argument to be a UserGroup in
our case.

Reference:
02966a30dd/django/db/models/base.py (L537-L546)
This commit is contained in:
Zixuan James Li
2023-07-12 13:30:23 -04:00
committed by Tim Abbott
parent 3bf83e8830
commit 1af50548ae

View File

@@ -194,7 +194,7 @@ def fix_streams_can_remove_subscribers_group_column(data: TableData, realm: Real
name=UserGroup.ADMINISTRATORS_GROUP_NAME, realm=realm, is_system_group=True
)
for stream in data[table]:
stream["can_remove_subscribers_group_id"] = admins_group.id
stream["can_remove_subscribers_group"] = admins_group
def create_subscription_events(data: TableData, realm_id: int) -> None:
@@ -986,6 +986,9 @@ def do_import_realm(import_dir: Path, subdomain: str, processes: int = 1) -> Rea
fix_datetime_fields(data, "zerver_stream")
re_map_foreign_keys(data, "zerver_stream", "realm", related_table="realm")
if role_system_groups_dict is not None:
# Because the system user groups are missing, we manually set up
# the defaults for can_remove_subscribers_group for all the
# streams.
fix_streams_can_remove_subscribers_group_column(data, realm)
else:
re_map_foreign_keys(