Invalid Version Parsing in docker-py with docker.io Versions Containing Suffixes (e.g., 20.10.24+dfsg1)
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.2k
- Forks
- 1.7k
- Avg merge
- 13d 8h
- Merged PRs (30d)
- 2
Description
Hello,
I'm Tommaso from Kathará, a network emulator based on Docker containers.
We use docker-py to interface with the Docker daemon, and we have encountered an issue when using the version_lt function (and similar ones like version_ge) from the utils module of docker-py with certain versions of docker.io. Specifically, this issue arises when the Docker version string includes additional characters, such as 20.10.24+dfsg1 (docker.io) (e.g., KatharaFramework/Kathara#301, KatharaFramework/Kathara#309).
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.11/dist-packages/docker/utils/utils.py", line 225, in version_lt
return compare_version(v1, v2) > 0
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/docker/utils/utils.py", line 214, in compare_version
s1 = StrictVersion(v1)
^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/setuptools/_distutils/version.py", line 54, in __init__
self.parse(vstring)
File "/usr/lib/python3/dist-packages/setuptools/_distutils/version.py", line 157, in parse
raise ValueError("invalid version number '%s'" % vstring)
ValueError: invalid version number '20.10.24+dfsg1'
I understand that docker.io is not officially released by Docker, so I am unsure if this falls within your intended scope. However, I wanted to bring this to your attention in case you are interested in addressing the compatibility issue.
STEP TO REPRODUCE
- Run a container and enter it:
docker run -ti --rm debian:latest bash
- Install required packages:
apt update
apt install python3 python3-pip
- Install docker-py:
python3 -m pip install docker-py --break-system-packages
- Enter a Python shell:
python3
- Reproduce the error:
from docker.utils import version_lt
version_lt("20.10.24+dfsg1", "20.10.0")
- Get the error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.11/dist-packages/docker/utils/utils.py", line 225, in version_lt
return compare_version(v1, v2) < 0
File "/usr/local/lib/python3.11/dist-packages/docker/utils/utils.py", line 24, in compare_version
a = StrictVersion(vA)
File "/usr/lib/python3.11/dist-packages/setuptools/_distutils/version.py", line 41, in __init__
self.parse(vstring)
File "/usr/lib/python3.11/dist-packages/setuptools/_distutils/version.py", line 157, in parse
raise ValueError(f"invalid version number '{vstring}'")
ValueError: invalid version number '20.10.24+dfsg1'
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in docker/utils/utils.py at compare_version and the version_lt/version_ge helpers, then run the reproduction with 20.10.24+dfsg1 and 20.10.0. Check how version strings with suffixes should compare, and add coverage for the reported case. Done means these helpers no longer raise ValueError for the reported docker.io version while retaining correct comparisons.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100