Skip to content

Commit 3a6a179

Browse files
Marcin Juszkiewiczyoctozepto
authored andcommitted
Use jinja2.pass_context instead of contextfilter
The contextfilter decorator was deprecated in jinja2 3.0.0, and has been dropped in 3.1.0. This results in the following warning, and failed attempts to use filters: [WARNING]: Skipping plugin (filters.py) as it seems to be invalid: module 'jinja2' has no attribute 'contextfilter' This change switches to use the pass_context decorator. The minimum version of Jinja2 is raised to 3 to ensure pass_context is present. This change has been updated to also support Jinja2 2.x releases, since the Wallaby upper constraints specify 2.11.3. In practice, most users will not use UC to install kolla. CoAuthored-by: Mark Goddard <[email protected]> Change-Id: I5efab66e487e06abd1a56af97d7e7caa1ebc880d
1 parent ebb2b09 commit 3a6a179

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

kolla/template/filters.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from jinja2 import contextfilter
15+
# NOTE: jinja2 3.1.0 dropped contextfilter in favour of pass_context.
16+
try:
17+
from jinja2 import pass_context
18+
except ImportError:
19+
from jinja2 import contextfilter as pass_context
20+
1621
from jinja2 import Undefined
1722

1823

19-
@contextfilter
24+
@pass_context
2025
def customizable(context, val_list, call_type):
2126
# NOTE(mgoddard): Don't try to customise undefined values. There are cases
2227
# where this might happen, for example using a generic template overrides

kolla/template/methods.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515
import os
1616
import yaml
1717

18-
from jinja2 import contextfunction
18+
# NOTE: jinja2 3.1.0 dropped contextfilter in favour of pass_context.
19+
try:
20+
from jinja2 import pass_context
21+
except ImportError:
22+
from jinja2 import contextfilter as pass_context
1923

2024

2125
def debian_package_install(packages, clean_package_cache=True):
@@ -71,7 +75,7 @@ def debian_package_install(packages, clean_package_cache=True):
7175
return ' && '.join(cmds)
7276

7377

74-
@contextfunction
78+
@pass_context
7579
def handle_repos(context, reponames, mode):
7680
"""NOTE(hrw): we need to handle CentOS, Debian and Ubuntu with one macro.
7781
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
Fixes an issue seen when using Jinja2 3.1.0.

0 commit comments

Comments
 (0)