Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
typing: Narrow connection type before accessing pg_version.
Zixuan James Li10dc6ea39eba
diff --git a/zerver/management/commands/backup.py b/zerver/management/commands/backup.pyindex e31e9aa2919..829c7213da5 100644--- a/zerver/management/commands/backup.py+++ b/zerver/management/commands/backup.py@@ -2,11 +2,12 @@ import osimport reimport tempfilefrom argparse import ArgumentParser, RawTextHelpFormatter-from typing import Any+from typing import TYPE_CHECKING, Anyfrom django.conf import settingsfrom django.core.management.base import CommandParserfrom django.db import connection+from django.db.backends.postgresql.base import DatabaseWrapperfrom django.utils.timezone import now as timezone_nowfrom scripts.lib.zulip_tools import TIMESTAMP_FORMAT, parse_os_release, run@@ -51,6 +52,12 @@ class Command(ZulipBaseCommand):members.append("zulip-backup/os-version")with open(os.path.join(tmp, "zulip-backup", "postgres-version"), "w") as f:+ # We are accessing a backend specific attribute via a proxy object, whose type+ # cannot be narrowed with a regular isinstance assertion.+ # This can be potentially fixed more cleanly with the recently added+ # connection.get_database_version().+ if TYPE_CHECKING:+ assert isinstance(connection, DatabaseWrapper)print(connection.pg_version, file=f)members.append("zulip-backup/postgres-version")