From 2c65f37e1338ac58573b26b402457b6111cf8cfd Mon Sep 17 00:00:00 2001 From: Amadeus Date: Tue, 6 Oct 2026 14:47:24 -0300 Subject: [PATCH] bug: parse docker images with a registry port DockerImage.parse split on every colon, so localhost:5000/lean was read as name 'localhost' with tag '5000/lean' and localhost:5000/lean:latest raised ValueError. Only the part after the last colon is a tag, and only when it does not contain a slash. Co-Authored-By: Claude Opus 5.5 --- lean/models/docker.py | 6 +++--- tests/models/test_docker.py | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lean/models/docker.py b/lean/models/docker.py index 4ed2c5f8..9a37e510 100644 --- a/lean/models/docker.py +++ b/lean/models/docker.py @@ -25,9 +25,9 @@ def parse(cls, image: str) -> 'DockerImage': :param image: the input value :return: the DockerImage object containing the name and the tag of the image """ - if ":" in image: - name, tag = image.split(":") - else: + # A colon can also separate a registry host from its port, the tag is only what follows the last one + name, separator, tag = image.rpartition(":") + if separator == "" or "/" in tag: name = image tag = "latest" diff --git a/tests/models/test_docker.py b/tests/models/test_docker.py index 1da2ccca..33fb2a74 100644 --- a/tests/models/test_docker.py +++ b/tests/models/test_docker.py @@ -21,7 +21,11 @@ ("lean:123", "lean", "123"), ("quantconnect/lean", "quantconnect/lean", "latest"), ("quantconnect/lean:latest", "quantconnect/lean", "latest"), - ("quantconnect/lean:123", "quantconnect/lean", "123")]) + ("quantconnect/lean:123", "quantconnect/lean", "123"), + ("localhost:5000/lean", "localhost:5000/lean", "latest"), + ("localhost:5000/lean:123", "localhost:5000/lean", "123"), + ("registry.example.com:5000/quantconnect/lean:123", + "registry.example.com:5000/quantconnect/lean", "123")]) def test_docker_image_name_parse_parses_value(value: str, name: str, tag: str) -> None: result = DockerImage.parse(value)