fix(cp): fall back to __opts__ when __file_client__ is not packed#69739
Open
dwoz wants to merge 1 commit into
Open
fix(cp): fall back to __opts__ when __file_client__ is not packed#69739dwoz wants to merge 1 commit into
dwoz wants to merge 1 commit into
Conversation
cp._client() used `if __file_client__:`, which raises LoaderError instead of being falsey when the executing loader has not packed a __file_client__ context (loaders other than minion_mods, e.g. the resource module loader). The raise short-circuited the __opts__ fallback, so cp.cache_file and every salt:// fetch failed with KeyError: '__file_client__'. Guard the lookup and fall back to building a file client from __opts__. Fixes saltstack#69734
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.
What does this PR do?
salt.modules.cp._client()did:__file_client__is aNamedLoaderContext. When the loader executing thecpmodule has not packed a
__file_client__(any loader other thanminion_modsthat omits a file client — e.g. the resource module loader),evaluating
if __file_client__:raisesLoaderErrorrather than returning afalsey value. That raise short-circuits the intended
__opts__fallback, socp.cache_file— and therefore everysalt://fetch a state performs —fails with
KeyError: '__file_client__'.This guards the context lookup and falls back to building a file client from
__opts__when the context is missing/None.What issues does this PR fix or reference?
Fixes #69734
Previous Behavior
cp._client()raisedLoaderError/KeyError: '__file_client__'on any loaderthat did not pack a file client, breaking
salt://fetches.New Behavior
cp._client()returns the packed file client when present, otherwise builds onefrom
__opts__— no exception.Tests written?
Yes —
tests/pytests/unit/modules/test_cp.py:test__client_returns_packed_file_clienttest__client_falls_back_when_file_client_not_packedCommits signed with GPG?
No