From 5b3597897abc16e5c8420dabe37dcd9065d0c6e4 Mon Sep 17 00:00:00 2001 From: Gyubong Lee Date: Thu, 24 Oct 2024 10:29:33 +0900 Subject: [PATCH] fix: Disallow `None` id encoding in `AsyncNode.to_global_id()` (#2898) --- changes/2898.fix.md | 1 + src/ai/backend/manager/api/schema.graphql | 4 +--- src/ai/backend/manager/models/container_registry.py | 2 +- src/ai/backend/manager/models/gql_relay.py | 6 ++++-- 4 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 changes/2898.fix.md diff --git a/changes/2898.fix.md b/changes/2898.fix.md new file mode 100644 index 0000000000..95c9ba6076 --- /dev/null +++ b/changes/2898.fix.md @@ -0,0 +1 @@ +Disallow `None` id encoding in `AsyncNode.to_global_id()`. diff --git a/src/ai/backend/manager/api/schema.graphql b/src/ai/backend/manager/api/schema.graphql index d541126aa0..628b65c7b5 100644 --- a/src/ai/backend/manager/api/schema.graphql +++ b/src/ai/backend/manager/api/schema.graphql @@ -1362,9 +1362,7 @@ type ContainerRegistryNode implements Node { """The ID of the object""" id: ID! - """ - Added in 24.09.0. The undecoded UUID type id of DB container_registries row. - """ + """Added in 24.09.0. The UUID type id of DB container_registries row.""" row_id: UUID name: String diff --git a/src/ai/backend/manager/models/container_registry.py b/src/ai/backend/manager/models/container_registry.py index 105a02aa1a..cbf46fcd1d 100644 --- a/src/ai/backend/manager/models/container_registry.py +++ b/src/ai/backend/manager/models/container_registry.py @@ -264,7 +264,7 @@ class Meta: description = "Added in 24.09.0." row_id = graphene.UUID( - description="Added in 24.09.0. The undecoded UUID type id of DB container_registries row." + description="Added in 24.09.0. The UUID type id of DB container_registries row." ) name = graphene.String() url = graphene.String(required=True, description="Added in 24.09.0.") diff --git a/src/ai/backend/manager/models/gql_relay.py b/src/ai/backend/manager/models/gql_relay.py index 0ed5cfa398..d7f6d7f80e 100644 --- a/src/ai/backend/manager/models/gql_relay.py +++ b/src/ai/backend/manager/models/gql_relay.py @@ -143,8 +143,10 @@ async def node_resolver(cls, only_type, root, info, id): return await cls.get_node_from_global_id(info, id, only_type=only_type) @staticmethod - def to_global_id(type_, id) -> str: - return base64(f"{type_}:{id}") + def to_global_id(type_, id_) -> str: + if id_ is None: + raise Exception("Encoding None value as Global ID is not allowed.") + return base64(f"{type_}:{id_}") @classmethod def resolve_global_id(cls, info, global_id: str) -> tuple[str, str]: