Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi all 👋 Thanks for the work here - I've found it really helpful for several projects.
I'd like to discuss changing the behavior of
Model.short_id
from returning a 10 character string to a 12 character string which aligns more closely with the docker cli. It looks like this has been requested previously by #1491 and #2660.For example (from the docs), running
docker ps
without explicitly setting--no-trunc
:It looks like 12 character ids were once the intended behavior - the object reprs in the docker-py documentation from #1186 show 12 digit ids:
The specific issue I'm having is that the 12 character container ID is used by docker as a container's default hostname. Here's a minimal example of a container trying to connect to itself by hostname:
API requests treat the id as a variable width prefix and returns valid responses as long as the prefix doesn't match multiple resources. So I think using 12 characters shouldn't break backwards compatibility for code that currently uses the 10 character
short_id
.Here's a first pass at the implementation.
short_id
for classes that inherit fromdocker.models.resource.Model
and a 19 charactershort_id
forImage
ids prefixed bysha256:
.fake_api
ids to 64 characters.ImageTest.test_short_id
to expect a 12 character response.ContainerTest.test_short_id
to expect a 12 character response.This currently fail flake8's E501 (line > 79 characters) requirement in a few places but I left the formatting as is for now since there are existing docstrings which fail E501 and it made the changes more readable. Happy to tweak to your preference.
Closes #1491
Closes #2660