[PR #10359/16d6e4a8 backport][stable-9] dependent lookup: avoid deprecated ansible-core 2.19 functionality (#10364)

dependent lookup: avoid deprecated ansible-core 2.19 functionality (#10359)

* Avoid deprecated ansible-core 2.19 functionality.

* Adjust unit tests.

(cherry picked from commit 16d6e4a8e5)

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
patchback[bot] 2025-07-08 06:52:39 +02:00 committed by GitHub
parent 68b233aa96
commit d5f3e6fa7f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 9 additions and 6 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- "dependent lookup plugin - avoid deprecated ansible-core 2.19 functionality (https://github.com/ansible-collections/community.general/pull/10359)."

View file

@ -210,7 +210,10 @@ class LookupModule(LookupBase):
result = [] result = []
if len(terms) > 0: if len(terms) > 0:
templar = Templar(loader=self._templar._loader) if HAS_DATATAGGING:
templar = self._templar.copy_with_new_env(available_variables={})
else:
templar = Templar(loader=self._templar._loader)
data = [] data = []
vars_so_far = set() vars_so_far = set()
for index, term in enumerate(terms): for index, term in enumerate(terms):

View file

@ -9,10 +9,9 @@ from __future__ import absolute_import, division, print_function
__metaclass__ = type __metaclass__ = type
from ansible.template import Templar
from ansible_collections.community.internal_test_tools.tests.unit.compat.unittest import TestCase from ansible_collections.community.internal_test_tools.tests.unit.compat.unittest import TestCase
from ansible_collections.community.internal_test_tools.tests.unit.compat.mock import (
MagicMock,
)
from ansible_collections.community.internal_test_tools.tests.unit.utils.trust import make_trusted from ansible_collections.community.internal_test_tools.tests.unit.utils.trust import make_trusted
from ansible.plugins.loader import lookup_loader from ansible.plugins.loader import lookup_loader
@ -20,8 +19,7 @@ from ansible.plugins.loader import lookup_loader
class TestLookupModule(TestCase): class TestLookupModule(TestCase):
def setUp(self): def setUp(self):
templar = MagicMock() templar = Templar(loader=None)
templar._loader = None
self.lookup = lookup_loader.get("community.general.dependent", templar=templar) self.lookup = lookup_loader.get("community.general.dependent", templar=templar)
def test_empty(self): def test_empty(self):