Skip to content

Commit

Permalink
fix: Remove graphene field's deprecation/description setter function (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
fregataa authored Feb 15, 2024
1 parent 46fa039 commit bbcee9a
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 87 deletions.
1 change: 1 addition & 0 deletions changes/1734.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Write graphene field's deprecation/description message string directly instead of using message generation functions.
117 changes: 47 additions & 70 deletions src/ai/backend/manager/models/resource_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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):
Expand Down
5 changes: 2 additions & 3 deletions src/ai/backend/manager/models/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 0 additions & 14 deletions src/ai/backend/manager/models/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit bbcee9a

Please sign in to comment.