Return 12 character short_ids#2862
Merged
Merged
Conversation
Signed-off-by: Ben Fasoli <benfasoli@gmail.com>
|
Up, that doesn't seems like a big deal but it would improve the python API. I was thinking about creating a database storing container stats but I couldn't choose a coherent length for the short ID because of this python/docker cli discrepancy. |
Signed-off-by: Milas Bowman <milas.bowman@docker.com>
milas
approved these changes
Jul 28, 2022
Contributor
milas
left a comment
There was a problem hiding this comment.
Thanks for the improvement and tests! Will get this included in the upcoming 6.0.0 release 🙂
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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_idfrom 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 pswithout 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_idfor classes that inherit fromdocker.models.resource.Modeland a 19 charactershort_idforImageids prefixed bysha256:.fake_apiids to 64 characters.ImageTest.test_short_idto expect a 12 character response.ContainerTest.test_short_idto 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