Skip to content

[Bug]: cp.get_template throws KeyError when template has an import with contextΒ #68572

@Akrugerus

Description

@Akrugerus

What happened?

When upgrading from 3006.9 to 3006.10 we encountered an issue with cp.get_template similar to #67941 where calling cp.get_template on a template that has an import statement like {%- from 'my/map.jinja' import defaults with context -%} will throw AttributeError: 'NoneType' object has no attribute 'get'.

According to #67491 the bug in cp.push is fixed in 3006.13, but I have confirmed that this bug exists up to 3006.18 for cp.get_template.

Could be caused by #66997, as the context passed to template.render contains 'salt': <salt.utils.templates.AliasedLoader object at 0x7f52ca6b7b50>.

Recreating the bug is trivial:

salt://templates/file.j2

{%- from 'my/map.jinja' import defaults with context -%}
{{ defaults['foo'] }}

salt://my/map.jinja

{% set defaults = {'foo': 'bar'} %}

salt-call cp.get_template salt://templates/file.j2 ./file

Type of salt install

Official deb

Major version

3006.x

What supported OS are you seeing the problem on? Can select multiple. (If bug appears on an unsupported OS, please open a GitHub Discussion instead)

debian-12, debian-11, amazonlinux-2

salt --versions-report output

Salt Version:
          Salt: 3006.17

Python Version:
        Python: 3.10.19 (main, Oct 30 2025, 04:53:28) [GCC 11.2.0]

Dependency Versions:
          cffi: 2.0.0
      cherrypy: 18.10.0
  cryptography: 42.0.5
      dateutil: 2.8.1
     docker-py: Not Installed
         gitdb: Not Installed
     gitpython: Not Installed
        Jinja2: 3.1.6
       libgit2: 1.6.4
  looseversion: 1.0.2
      M2Crypto: Not Installed
          Mako: Not Installed
       msgpack: 1.0.2
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     packaging: 24.0
     pycparser: 2.21
      pycrypto: Not Installed
  pycryptodome: 3.19.1
        pygit2: 1.12.2
  python-gnupg: 0.4.8
        PyYAML: 6.0.1
         PyZMQ: 23.2.0
        relenv: 0.21.2
         smmap: Not Installed
       timelib: 0.3.0
       Tornado: 4.5.3
           ZMQ: 4.3.4

System Versions:
          dist: amzn 2
        locale: utf-8
       machine: x86_64
       release: 5.10.245-241.978.amzn2.x86_64
        system: Linux
       version: Amazon Linux 2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugbroken, incorrect, or confusing behaviorneeds-triage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions