zilencer: Use proper typing for update_remote_realm_data_for_server.

This is an obvious improvement to the typing and more natural than the
forced dict() conversion.
This commit is contained in:
Mateusz Mandera 2023-11-27 01:53:08 +01:00 committed by Tim Abbott
parent 2f91179c1e
commit 6f2d4f1af2
1 changed files with 12 additions and 12 deletions

View File

@ -526,9 +526,9 @@ def batch_create_table_data(
def update_remote_realm_data_for_server( def update_remote_realm_data_for_server(
server: RemoteZulipServer, server_realms_info: List[Dict[str, Any]] server: RemoteZulipServer, server_realms_info: List[RealmDataForAnalytics]
) -> None: ) -> None:
uuids = [realm["uuid"] for realm in server_realms_info] uuids = [realm.uuid for realm in server_realms_info]
already_registered_remote_realms = RemoteRealm.objects.filter(uuid__in=uuids, server=server) already_registered_remote_realms = RemoteRealm.objects.filter(uuid__in=uuids, server=server)
already_registered_uuids = { already_registered_uuids = {
remote_realm.uuid for remote_realm in already_registered_remote_realms remote_realm.uuid for remote_realm in already_registered_remote_realms
@ -537,14 +537,14 @@ def update_remote_realm_data_for_server(
new_remote_realms = [ new_remote_realms = [
RemoteRealm( RemoteRealm(
server=server, server=server,
uuid=realm["uuid"], uuid=realm.uuid,
uuid_owner_secret=realm["uuid_owner_secret"], uuid_owner_secret=realm.uuid_owner_secret,
host=realm["host"], host=realm.host,
realm_deactivated=realm["deactivated"], realm_deactivated=realm.deactivated,
realm_date_created=timestamp_to_datetime(realm["date_created"]), realm_date_created=timestamp_to_datetime(realm.date_created),
) )
for realm in server_realms_info for realm in server_realms_info
if realm["uuid"] not in already_registered_uuids if realm.uuid not in already_registered_uuids
] ]
try: try:
@ -552,7 +552,7 @@ def update_remote_realm_data_for_server(
except IntegrityError: except IntegrityError:
raise JsonableError(_("Duplicate registration detected.")) raise JsonableError(_("Duplicate registration detected."))
uuid_to_realm_dict = {str(realm["uuid"]): realm for realm in server_realms_info} uuid_to_realm_dict = {str(realm.uuid): realm for realm in server_realms_info}
remote_realms_to_update = [] remote_realms_to_update = []
remote_realm_audit_logs = [] remote_realm_audit_logs = []
now = timezone_now() now = timezone_now()
@ -567,7 +567,7 @@ def update_remote_realm_data_for_server(
("realm_deactivated", "deactivated"), ("realm_deactivated", "deactivated"),
]: ]:
old_value = getattr(remote_realm, remote_realm_attr) old_value = getattr(remote_realm, remote_realm_attr)
new_value = realm[realm_dict_key] new_value = getattr(realm, realm_dict_key)
if old_value == new_value: if old_value == new_value:
continue continue
@ -577,7 +577,7 @@ def update_remote_realm_data_for_server(
server=server, server=server,
remote_id=None, remote_id=None,
remote_realm=remote_realm, remote_realm=remote_realm,
realm_id=realm["id"], realm_id=realm.id,
event_type=RemoteRealmAuditLog.REMOTE_REALM_VALUE_UPDATED, event_type=RemoteRealmAuditLog.REMOTE_REALM_VALUE_UPDATED,
event_time=now, event_time=now,
extra_data={ extra_data={
@ -657,7 +657,7 @@ def remote_server_post_analytics(
) )
if realms is not None: if realms is not None:
update_remote_realm_data_for_server(server, [dict(realm) for realm in realms]) update_remote_realm_data_for_server(server, realms)
remote_realm_counts = [ remote_realm_counts = [
RemoteRealmCount( RemoteRealmCount(