Skip to content

fix(cp): fall back to __opts__ when __file_client__ is not packed#69739

Open
dwoz wants to merge 1 commit into
saltstack:masterfrom
dwoz:fix/cp-client-file-client-loadererror
Open

fix(cp): fall back to __opts__ when __file_client__ is not packed#69739
dwoz wants to merge 1 commit into
saltstack:masterfrom
dwoz:fix/cp-client-file-client-loadererror

Conversation

@dwoz

@dwoz dwoz commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

salt.modules.cp._client() did:

if __file_client__:
    return __file_client__.value()
return salt.fileclient.get_file_client(__opts__.value())

__file_client__ is a NamedLoaderContext. When the loader executing the cp
module has not packed a __file_client__ (any loader other than
minion_mods that omits a file client — e.g. the resource module loader),
evaluating if __file_client__: raises LoaderError rather than returning a
falsey value. That raise short-circuits the intended __opts__ fallback, so
cp.cache_file — and therefore every salt:// 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() raised LoaderError/KeyError: '__file_client__' on any loader
that did not pack a file client, breaking salt:// fetches.

New Behavior

cp._client() returns the packed file client when present, otherwise builds one
from __opts__ — no exception.

Tests written?

Yes — tests/pytests/unit/modules/test_cp.py:

  • test__client_returns_packed_file_client
  • test__client_falls_back_when_file_client_not_packed

Commits signed with GPG?

No

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
@dwoz dwoz requested a review from a team as a code owner July 7, 2026 05:53
@dwoz dwoz added the test:full Run the full test suite label Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:full Run the full test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: cp._client() raises LoaderError (KeyError: '__file_client__') when __file_client__ is not packed (resource_modules loader)

1 participant