mypy: Upgrade mypy from 1.4.1 to 1.5.1.

_default_manager is the same as objects on most of our models. But
when a model class is stored in a variable, the type system doesn’t
know which model the variable is referring to, so it can’t know that
objects even exists (Django doesn’t add it if the user added a custom
manager of a different name). django-stubs used to incorrectly assume
it exists unconditionally, but it no longer does.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2023-09-05 11:25:23 -07:00
committed by Tim Abbott
parent c99c8f4640
commit 0ce6dcb905
15 changed files with 89 additions and 78 deletions

View File

@@ -465,17 +465,17 @@ CountT = TypeVar("CountT", bound=BaseCount)
def table_filtered_to_id(table: Type[CountT], key_id: int) -> QuerySet[CountT]:
if table == RealmCount:
return table.objects.filter(realm_id=key_id)
return table._default_manager.filter(realm_id=key_id)
elif table == UserCount:
return table.objects.filter(user_id=key_id)
return table._default_manager.filter(user_id=key_id)
elif table == StreamCount:
return table.objects.filter(stream_id=key_id)
return table._default_manager.filter(stream_id=key_id)
elif table == InstallationCount:
return table.objects.all()
return table._default_manager.all()
elif settings.ZILENCER_ENABLED and table == RemoteInstallationCount:
return table.objects.filter(server_id=key_id)
return table._default_manager.filter(server_id=key_id)
elif settings.ZILENCER_ENABLED and table == RemoteRealmCount:
return table.objects.filter(realm_id=key_id)
return table._default_manager.filter(realm_id=key_id)
else:
raise AssertionError(f"Unknown table: {table}")