openSUSE / salt

openSUSE and SUSE patches and backports for SaltStack
Apache License 2.0
22 stars 52 forks source link

Allow NamedLoaderContexts to be returned from loader #681

Closed vzhestkov closed 3 weeks ago

vzhestkov commented 4 weeks ago

What does this PR do?

Backport of https://github.com/saltstack/salt/pull/66649

It is useful in some cases to return NamedLoaderContexts from loaded functions. Instead of choking or requireing implimenters to call the context's value() method before being de-scoped, detect when a NamedLoaderContext has been returned and return the value from the current context.

What issues does this PR fix or reference?

https://github.com/saltstack/salt/pull/66364 was opened for upstream before, but they decided to put the fix to 3006.x and a bit different way. There was an unrelated bug opened when such behavior appered while testing. So no reference for now.

Previous Behavior

Could return the following instead of the proper dict:

demo.example.org:
    <salt.loader.context.NamedLoaderContext object at 0x7f31461b80a0>

New Behavior

Return the expected dict output

Merge requirements satisfied?

[NOTICE] Bug fixes or features added to Salt require tests.

Commits signed with GPG?

Yes/No

Please review Salt's Contributing Guide for best practices.

See GitHub's page on GPG signing for more information about signing commits with GPG.