zilencer: Avoid redefinition of row_objects.

Mypy disallows redefinition of a variable with different types.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>
This commit is contained in:
Zixuan James Li 2022-06-30 21:12:07 -04:00 committed by Tim Abbott
parent 7950baafe2
commit b7bb30f3cb
1 changed files with 13 additions and 9 deletions

View File

@ -1,11 +1,12 @@
import datetime import datetime
import logging import logging
from typing import Any, Dict, List, Optional, Union from typing import Any, Dict, List, Optional, Type, TypeVar, Union
from uuid import UUID from uuid import UUID
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.core.validators import URLValidator, validate_email from django.core.validators import URLValidator, validate_email
from django.db import IntegrityError, transaction from django.db import IntegrityError, transaction
from django.db.models import Model
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
from django.utils import timezone from django.utils import timezone
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
@ -314,10 +315,13 @@ def validate_incoming_table_data(
last_id = row["id"] last_id = row["id"]
ModelT = TypeVar("ModelT", bound=Model)
def batch_create_table_data( def batch_create_table_data(
server: RemoteZulipServer, server: RemoteZulipServer,
model: Any, model: Type[ModelT],
row_objects: Union[List[RemoteRealmCount], List[RemoteInstallationCount]], row_objects: List[ModelT],
) -> None: ) -> None:
BATCH_SIZE = 1000 BATCH_SIZE = 1000
while len(row_objects) > 0: while len(row_objects) > 0:
@ -388,7 +392,7 @@ def remote_server_post_analytics(
if realmauditlog_rows is not None: if realmauditlog_rows is not None:
validate_incoming_table_data(server, RemoteRealmAuditLog, realmauditlog_rows) validate_incoming_table_data(server, RemoteRealmAuditLog, realmauditlog_rows)
row_objects = [ remote_realm_counts = [
RemoteRealmCount( RemoteRealmCount(
property=row["property"], property=row["property"],
realm_id=row["realm"], realm_id=row["realm"],
@ -400,9 +404,9 @@ def remote_server_post_analytics(
) )
for row in realm_counts for row in realm_counts
] ]
batch_create_table_data(server, RemoteRealmCount, row_objects) batch_create_table_data(server, RemoteRealmCount, remote_realm_counts)
row_objects = [ remote_installation_counts = [
RemoteInstallationCount( RemoteInstallationCount(
property=row["property"], property=row["property"],
remote_id=row["id"], remote_id=row["id"],
@ -413,10 +417,10 @@ def remote_server_post_analytics(
) )
for row in installation_counts for row in installation_counts
] ]
batch_create_table_data(server, RemoteInstallationCount, row_objects) batch_create_table_data(server, RemoteInstallationCount, remote_installation_counts)
if realmauditlog_rows is not None: if realmauditlog_rows is not None:
row_objects = [ remote_realm_audit_logs = [
RemoteRealmAuditLog( RemoteRealmAuditLog(
realm_id=row["realm"], realm_id=row["realm"],
remote_id=row["id"], remote_id=row["id"],
@ -430,7 +434,7 @@ def remote_server_post_analytics(
) )
for row in realmauditlog_rows for row in realmauditlog_rows
] ]
batch_create_table_data(server, RemoteRealmAuditLog, row_objects) batch_create_table_data(server, RemoteRealmAuditLog, remote_realm_audit_logs)
return json_success(request) return json_success(request)