From 323cdbc9b2f704e0f929807e1056a3e5e35994f8 Mon Sep 17 00:00:00 2001 From: Gyubong Date: Fri, 22 Nov 2024 07:55:08 +0900 Subject: [PATCH 1/4] fix: None project issue --- src/ai/backend/manager/models/image.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ai/backend/manager/models/image.py b/src/ai/backend/manager/models/image.py index d4724f7db7..89ee98e2ac 100644 --- a/src/ai/backend/manager/models/image.py +++ b/src/ai/backend/manager/models/image.py @@ -35,6 +35,7 @@ ImageRegistry, ResourceSlot, ) +from ai.backend.common.utils import join_non_empty from ai.backend.logging import BraceStyleAdapter from ai.backend.manager.models.container_registry import ContainerRegistryRow @@ -264,7 +265,8 @@ def image_ref(self) -> ImageRef: image_name = "" _, tag = ImageRef.parse_image_tag(self.name.split(f"{self.registry}/", maxsplit=1)[1]) else: - image_and_tag = self.name.split(f"{self.registry}/{self.project}/", maxsplit=1)[1] + join = functools.partial(join_non_empty, sep="/") + image_and_tag = self.name.split(f"{join(self.registry, self.project)}/", maxsplit=1)[1] image_name, tag = ImageRef.parse_image_tag(image_and_tag) return ImageRef( From 831337b3bfa2d63a7768060dc138470bff8ecb2f Mon Sep 17 00:00:00 2001 From: Gyubong Date: Fri, 22 Nov 2024 08:00:58 +0900 Subject: [PATCH 2/4] chore: Add news fragment --- changes/3125.fix.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/3125.fix.md diff --git a/changes/3125.fix.md b/changes/3125.fix.md new file mode 100644 index 0000000000..aca040cad6 --- /dev/null +++ b/changes/3125.fix.md @@ -0,0 +1 @@ +Fix outdated image string join logic in `ImageRow.image_ref`. From 463e65d0e3931e2426e5ca95b2ca67d5276e2299 Mon Sep 17 00:00:00 2001 From: Gyubong Date: Fri, 22 Nov 2024 15:06:43 +0900 Subject: [PATCH 3/4] fix: Add type hint and prefer `partition` to `split` --- src/ai/backend/common/utils.py | 2 +- src/ai/backend/manager/models/image.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ai/backend/common/utils.py b/src/ai/backend/common/utils.py index 5d98b54d33..4eed2a0366 100644 --- a/src/ai/backend/common/utils.py +++ b/src/ai/backend/common/utils.py @@ -419,7 +419,7 @@ def is_ip_address_format(str: str) -> bool: return False -def join_non_empty(*args, sep): +def join_non_empty(*args: Optional[str], sep: str) -> str: """ Joins non-empty strings from the given arguments using the specified separator. """ diff --git a/src/ai/backend/manager/models/image.py b/src/ai/backend/manager/models/image.py index 89ee98e2ac..ae976a0dc8 100644 --- a/src/ai/backend/manager/models/image.py +++ b/src/ai/backend/manager/models/image.py @@ -266,7 +266,7 @@ def image_ref(self) -> ImageRef: _, tag = ImageRef.parse_image_tag(self.name.split(f"{self.registry}/", maxsplit=1)[1]) else: join = functools.partial(join_non_empty, sep="/") - image_and_tag = self.name.split(f"{join(self.registry, self.project)}/", maxsplit=1)[1] + _, _, image_and_tag = self.name.partition(f"{join(self.registry, self.project)}/") image_name, tag = ImageRef.parse_image_tag(image_and_tag) return ImageRef( From ea04241aea2dfd5dad63f7ba591cf232916bf17b Mon Sep 17 00:00:00 2001 From: Gyubong Date: Mon, 25 Nov 2024 11:23:43 +0900 Subject: [PATCH 4/4] fix: Use `removeprefix` --- src/ai/backend/manager/models/image.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ai/backend/manager/models/image.py b/src/ai/backend/manager/models/image.py index ae976a0dc8..b946f334c0 100644 --- a/src/ai/backend/manager/models/image.py +++ b/src/ai/backend/manager/models/image.py @@ -266,7 +266,7 @@ def image_ref(self) -> ImageRef: _, tag = ImageRef.parse_image_tag(self.name.split(f"{self.registry}/", maxsplit=1)[1]) else: join = functools.partial(join_non_empty, sep="/") - _, _, image_and_tag = self.name.partition(f"{join(self.registry, self.project)}/") + image_and_tag = self.name.removeprefix(f"{join(self.registry, self.project)}/") image_name, tag = ImageRef.parse_image_tag(image_and_tag) return ImageRef(