Guard MySQL size calculation returning None (#73331)

This commit is contained in:
Paulus Schoutsen 2022-06-10 12:49:58 -07:00 committed by GitHub
parent 2b07082cf6
commit 53b3d2ee87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,10 +5,9 @@ from sqlalchemy import text
from sqlalchemy.orm.session import Session
def db_size_bytes(session: Session, database_name: str) -> float:
def db_size_bytes(session: Session, database_name: str) -> float | None:
"""Get the mysql database size."""
return float(
session.execute(
size = session.execute(
text(
"SELECT ROUND(SUM(DATA_LENGTH + INDEX_LENGTH), 2) "
"FROM information_schema.TABLES WHERE "
@ -16,4 +15,8 @@ def db_size_bytes(session: Session, database_name: str) -> float:
),
{"database_name": database_name},
).first()[0]
)
if size is None:
return None
return float(size)