docker / docker/docker-py

Invalid Version Parsing in docker-py with docker.io Versions Containing Suffixes (e.g., 20.10.24+dfsg1)

Open
#3,288 1 comment 1 reaction 0 assignees View on GitHub

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

  1. Run a container and enter it:
docker run -ti --rm debian:latest bash
  1. Install required packages:
apt update  
apt install python3 python3-pip
  1. Install docker-py:
python3 -m pip install docker-py --break-system-packages
  1. Enter a Python shell:
python3
  1. Reproduce the error:
from docker.utils import version_lt
version_lt("20.10.24+dfsg1", "20.10.0")  
  1. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.