From bbcee9a5c9460777ca85be598b787c80c320fba4 Mon Sep 17 00:00:00 2001 From: Sanghun Lee Date: Thu, 15 Feb 2024 14:14:07 +0900 Subject: [PATCH] fix: Remove graphene field's deprecation/description setter function (#1734) --- changes/1734.fix.md | 1 + .../backend/manager/models/resource_policy.py | 117 +++++++----------- src/ai/backend/manager/models/storage.py | 5 +- src/ai/backend/manager/models/utils.py | 14 --- 4 files changed, 50 insertions(+), 87 deletions(-) create mode 100644 changes/1734.fix.md diff --git a/changes/1734.fix.md b/changes/1734.fix.md new file mode 100644 index 0000000000..ce8c444eed --- /dev/null +++ b/changes/1734.fix.md @@ -0,0 +1 @@ +Write graphene field's deprecation/description message string directly instead of using message generation functions. diff --git a/src/ai/backend/manager/models/resource_policy.py b/src/ai/backend/manager/models/resource_policy.py index d484d34d73..9e456ab17a 100644 --- a/src/ai/backend/manager/models/resource_policy.py +++ b/src/ai/backend/manager/models/resource_policy.py @@ -28,7 +28,6 @@ ) from .keypair import keypairs from .user import UserRole -from .utils import deprecation_reason_msg, description_msg if TYPE_CHECKING: from .gql import GraphQueryContext @@ -58,34 +57,6 @@ ) -def user_max_vfolder_count(required: bool = False): - return graphene.Int( - required=required, - description=description_msg("24.03.1", "Limitation of the number of user vfolders."), - ) - - -def user_max_quota_scope_size(required: bool = False): - return BigInt( - required=required, - description=description_msg("24.03.1", "Limitation of the quota size of user vfolders."), - ) - - -def project_max_vfolder_count(required: bool = False): - return graphene.Int( - required=required, - description=description_msg("24.03.1", "Limitation of the number of project vfolders."), - ) - - -def project_max_quota_scope_size(required: bool = False): - return BigInt( - required=required, - description=description_msg("24.03.1", "Limitation of the quota size of project vfolders."), - ) - - keypair_resource_policies = sa.Table( "keypair_resource_policies", mapper_registry.metadata, @@ -172,9 +143,9 @@ class KeyPairResourcePolicy(graphene.ObjectType): idle_timeout = BigInt() allowed_vfolder_hosts = graphene.JSONString() - max_vfolder_count = graphene.Int(deprecation_reason=deprecation_reason_msg("23.09.4")) - max_vfolder_size = BigInt(deprecation_reason=deprecation_reason_msg("23.09.4")) - max_quota_scope_size = BigInt(deprecation_reason=deprecation_reason_msg("23.09.4")) + max_vfolder_count = graphene.Int(deprecation_reason="Deprecated since 23.09.4") + max_vfolder_size = BigInt(deprecation_reason="Deprecated since 23.09.4") + max_quota_scope_size = BigInt(deprecation_reason="Deprecated since 23.09.4") @classmethod def from_row( @@ -324,18 +295,9 @@ class CreateKeyPairResourcePolicyInput(graphene.InputObjectType): max_containers_per_session = graphene.Int(required=True) idle_timeout = BigInt(required=True) allowed_vfolder_hosts = graphene.JSONString(required=False) - max_vfolder_count = graphene.Int( - required=False, - deprecation_reason=deprecation_reason_msg("23.09.4"), - ) - max_vfolder_size = BigInt( - required=False, - deprecation_reason=deprecation_reason_msg("23.09.4"), - ) - max_quota_scope_size = BigInt( - required=False, - deprecation_reason=deprecation_reason_msg("23.09.4"), - ) + max_vfolder_count = graphene.Int(required=False, deprecation_reason="Deprecated since 23.09.4") + max_vfolder_size = BigInt(required=False, deprecation_reason="Deprecated since 23.09.4") + max_quota_scope_size = BigInt(required=False, deprecation_reason="Deprecated since 23.09.4") class ModifyKeyPairResourcePolicyInput(graphene.InputObjectType): @@ -347,18 +309,9 @@ class ModifyKeyPairResourcePolicyInput(graphene.InputObjectType): max_containers_per_session = graphene.Int(required=False) idle_timeout = BigInt(required=False) allowed_vfolder_hosts = graphene.JSONString(required=False) - max_vfolder_count = graphene.Int( - required=False, - deprecation_reason=deprecation_reason_msg("23.09.4"), - ) - max_vfolder_size = BigInt( - required=False, - deprecation_reason=deprecation_reason_msg("23.09.4"), - ) - max_quota_scope_size = BigInt( - required=False, - deprecation_reason=deprecation_reason_msg("23.09.4"), - ) + max_vfolder_count = graphene.Int(required=False, deprecation_reason="Deprecated since 23.09.4") + max_vfolder_size = BigInt(required=False, deprecation_reason="Deprecated since 23.09.4") + max_quota_scope_size = BigInt(required=False, deprecation_reason="Deprecated since 23.09.4") class CreateKeyPairResourcePolicy(graphene.Mutation): @@ -471,9 +424,13 @@ class UserResourcePolicy(graphene.ObjectType): id = graphene.ID(required=True) name = graphene.String(required=True) created_at = GQLDateTime(required=True) - max_vfolder_count = user_max_vfolder_count() - max_quota_scope_size = user_max_quota_scope_size() - max_vfolder_size = BigInt(deprecation_reason=deprecation_reason_msg("23.09.1")) + max_vfolder_count = graphene.Int( + description="Added since 24.03.1. Limitation of the number of user vfolders." + ) + max_quota_scope_size = BigInt( + description="Added since 24.03.1. Limitation of the quota size of user vfolders." + ) + max_vfolder_size = BigInt(deprecation_reason="Deprecated since 23.09.1") @classmethod def from_row( @@ -545,13 +502,21 @@ async def batch_load_by_user( class CreateUserResourcePolicyInput(graphene.InputObjectType): - max_vfolder_count = user_max_vfolder_count() - max_quota_scope_size = user_max_quota_scope_size() + max_vfolder_count = graphene.Int( + description="Added since 24.03.1. Limitation of the number of user vfolders." + ) + max_quota_scope_size = BigInt( + description="Added since 24.03.1. Limitation of the quota size of user vfolders." + ) class ModifyUserResourcePolicyInput(graphene.InputObjectType): - max_vfolder_count = user_max_vfolder_count() - max_quota_scope_size = user_max_quota_scope_size() + max_vfolder_count = graphene.Int( + description="Added since 24.03.1. Limitation of the number of user vfolders." + ) + max_quota_scope_size = BigInt( + description="Added since 24.03.1. Limitation of the quota size of user vfolders." + ) class CreateUserResourcePolicy(graphene.Mutation): @@ -648,9 +613,13 @@ class ProjectResourcePolicy(graphene.ObjectType): id = graphene.ID(required=True) name = graphene.String(required=True) created_at = GQLDateTime(required=True) - max_vfolder_count = project_max_vfolder_count() - max_quota_scope_size = project_max_quota_scope_size() - max_vfolder_size = BigInt(deprecation_reason=deprecation_reason_msg("23.09.1")) + max_vfolder_count = graphene.Int( + description="Added since 24.03.1. Limitation of the number of project vfolders." + ) + max_quota_scope_size = BigInt( + description="Added since 24.03.1. Limitation of the quota size of project vfolders." + ) + max_vfolder_size = BigInt(deprecation_reason="Deprecated since 23.09.1") @classmethod def from_row( @@ -723,13 +692,21 @@ async def batch_load_by_project( class CreateProjectResourcePolicyInput(graphene.InputObjectType): - max_vfolder_count = project_max_vfolder_count() - max_quota_scope_size = project_max_quota_scope_size() + max_vfolder_count = graphene.Int( + description="Added since 24.03.1. Limitation of the number of project vfolders." + ) + max_quota_scope_size = BigInt( + description="Added since 24.03.1. Limitation of the quota size of project vfolders." + ) class ModifyProjectResourcePolicyInput(graphene.InputObjectType): - max_vfolder_count = project_max_vfolder_count() - max_quota_scope_size = project_max_quota_scope_size() + max_vfolder_count = graphene.Int( + description="Added since 24.03.1. Limitation of the number of project vfolders." + ) + max_quota_scope_size = BigInt( + description="Added since 24.03.1. Limitation of the quota size of project vfolders." + ) class CreateProjectResourcePolicy(graphene.Mutation): diff --git a/src/ai/backend/manager/models/storage.py b/src/ai/backend/manager/models/storage.py index e891513ca7..7cc1939c4e 100644 --- a/src/ai/backend/manager/models/storage.py +++ b/src/ai/backend/manager/models/storage.py @@ -30,7 +30,6 @@ from ..api.exceptions import InvalidAPIParameters, VFolderOperationFailed from ..exceptions import InvalidArgument from .base import Item, PaginatedList -from .utils import description_msg if TYPE_CHECKING: from .gql import GraphQueryContext @@ -209,9 +208,9 @@ class Meta: performance_metric = graphene.JSONString() usage = graphene.JSONString() proxy = graphene.String( - description=description_msg("24.03.0", "Name of the proxy which this volume belongs to.") + description="Added since 24.03.0. Name of the proxy which this volume belongs to." ) - name = graphene.String(description=description_msg("24.03.0", "Name of the storage.")) + name = graphene.String(description="Added since 24.03.0. Name of the storage.") async def resolve_hardware_metadata(self, info: graphene.ResolveInfo) -> HardwareMetadata: ctx: GraphQueryContext = info.context diff --git a/src/ai/backend/manager/models/utils.py b/src/ai/backend/manager/models/utils.py index ad6e274c46..39fdf28289 100644 --- a/src/ai/backend/manager/models/utils.py +++ b/src/ai/backend/manager/models/utils.py @@ -383,17 +383,3 @@ def agg_to_array(column: sa.Column) -> sa.sql.functions.Function: def is_db_retry_error(e: Exception) -> bool: return isinstance(e, DBAPIError) and getattr(e.orig, "pgcode", None) == "40001" - - -def description_msg(version: str, detail: str | None = None) -> str: - val = f"Added since {version}." - if detail: - val = f"{val} {detail}" - return val - - -def deprecation_reason_msg(version: str, detail: str | None = None) -> str: - val = f"Deprecated since {version}." - if detail: - val = f"{val} {detail}" - return val