Repository navigation
Conversation
from_context('typo') silently fell back to the default local socket,
so calls could reach the wrong engine. Add a strict flag to
ContextAPI.kwargs_from_context and use it in from_context() when a name
is passed explicitly. from_env() and from_context() without a name keep
their lenient DOCKER_CONTEXT behaviour.
Fixes docker#3468
Signed-off-by: Beehtrix <walkin_danger@hotmail.com>
get_context('') treats the empty string as no name and returns the current context, so from_context('') silently fell back. Raise ContextNotFound instead.
Signed-off-by: Beehtrix <walkin_danger@hotmail.com>
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.
Fixes #3468
docker.from_context("typo")returned a client for the default local socket, becauseContextAPI.kwargs_from_context()returns{}when the context is missing. A mistyped remote context name therefore sent calls to the local engine.Changes:
ContextAPI.kwargs_from_context()takes a newstrict=Falseargument. Withstrict=Trueit raisesdocker.errors.ContextNotFound(name), the same exceptionremove_context()andset_current_context()use.DockerClient.from_context()passesstrict=Trueonly whennameis given.from_context()with no name, andfrom_env()with an unknownDOCKER_CONTEXT, still fall back to the default socket as before, as the issue suggests.from_context("")) also raisesContextNotFoundinstead of falling back.Tests (tests/unit/client_test.py): unknown name raises, no name with a bogus
DOCKER_CONTEXTdoes not raise, strict mode raises, and an empty name raises. The existingtest_from_context_uses_named_contextnow expectsstrict=True. On main the three new tests fail (3 failed in client_test.py); with the fixclient_test.pypluscontext_test.pygive 30 passed, 5 skipped.Checks not run / caveats:
tests/unithas 8 failures with and without this change (identical count on main). I did not investigate them.ruff checkover the whole repo reports 68 existing errors on main as well. Selected rules E,F,W,I on the three changed files pass.