Modify ↓
#13477 closed defect (fixed)
ImportError: cannot import name 'contextfilter' from 'jinja2'
Reported by: | Ryan J Ollos | Owned by: | Jun Omae |
---|---|---|---|
Priority: | normal | Milestone: | 1.5.4 |
Component: | web frontend | Version: | |
Severity: | normal | Keywords: | |
Cc: | Branch: | ||
Release Notes: |
Fixed incompatible with Jinja2 3.1. |
||
API Changes: | |||
Internal Changes: |
Description
$ pip list | grep Jinja Jinja2 3.1.1
Traceback (most recent call last): File "/Users/rjollos/Documents/Workspace/trac-dev/teo-rjollos.git/contrib/checkwiki.py", line 22, in <module> from trac.test import EnvironmentStub, Mock, MockPerm File "/Users/rjollos/Documents/Workspace/trac-dev/teo-rjollos.git/trac/test.py", line 47, in <module> from trac.env import Environment File "/Users/rjollos/Documents/Workspace/trac-dev/teo-rjollos.git/trac/env.py", line 52, in <module> from trac.web.chrome import Chrome File "/Users/rjollos/Documents/Workspace/trac-dev/teo-rjollos.git/trac/web/chrome.py", line 40, in <module> from trac.mimeview.api import RenderingContext, get_mimetype File "/Users/rjollos/Documents/Workspace/trac-dev/teo-rjollos.git/trac/mimeview/__init__.py", line 14, in <module> from trac.mimeview.api import * File "/Users/rjollos/Documents/Workspace/trac-dev/teo-rjollos.git/trac/mimeview/api.py", line 70, in <module> from trac.resource import Resource File "/Users/rjollos/Documents/Workspace/trac-dev/teo-rjollos.git/trac/resource.py", line 21, in <module> from trac.util.presentation import classes File "/Users/rjollos/Documents/Workspace/trac-dev/teo-rjollos.git/trac/util/presentation.py", line 24, in <module> from jinja2 import Undefined, contextfilter, evalcontextfilter ImportError: cannot import name 'contextfilter' from 'jinja2' (/Users/rjollos/.pyenv/versions/trac-py310/lib/python3.10/site-packages/jinja2/__init__.py) make: *** [update-help] Error 1
Attachments (0)
Change History (6)
comment:1 by , 3 years ago
comment:2 by , 3 years ago
Milestone: | 1.4.4 → 1.5.4 |
---|
Changing milestone to 1.5.x because Jinja2 doesn't support Python 2.7 since 3.0.0.
comment:3 by , 3 years ago
Verified unit tests passing with:
- Jinja2 3.1.1 on Python 3.9
- Jinja2 3.0.1 on Python 3.6, 3.7 and 3.8
- Jinja2 2.11.3 on Python 3.5
-
trac/util/presentation.py
commit 12146a3576d8e0f0629251564d0d863201643c8a (HEAD -> t13477) Author: Jun Omae <jun66j5@gmail.com> Date: Mon Apr 11 18:54:23 2022 +0900 (#13477) Use `pass_context` and `pass_eval_context` instead of deprecated `contextfilter` and `evalcontextfilter` since Jinja2 3.1 diff --git a/trac/util/presentation.py b/trac/util/presentation.py index 23232d55c..b53a12c2b 100644
a b from datetime import datetime 21 21 from math import ceil 22 22 import re 23 23 24 from jinja2 import Undefined , contextfilter, evalcontextfilter24 from jinja2 import Undefined 25 25 from jinja2.filters import make_attrgetter 26 try: 27 from jinja2 import pass_context, pass_eval_context 28 except ImportError: 29 from jinja2 import (contextfilter as pass_context, 30 evalcontextfilter as pass_eval_context) 26 31 27 32 from trac.core import TracError 28 33 from .datefmt import to_utimestamp, utc … … def jinja2_update(jenv): 72 77 73 78 # -- Jinja2 custom filters 74 79 75 @ evalcontextfilter80 @pass_eval_context 76 81 def htmlattr_filter(_eval_ctx, d, autospace=True): 77 82 """Create an SGML/XML attribute string based on the items in a dict. 78 83 … … def group(iterable, num, predicate=None): 259 264 yield tuple(buf) 260 265 261 266 262 @ contextfilter267 @pass_context 263 268 def groupattr_filter(_eval_ctx, iterable, num, attr, *args, **kwargs): 264 269 """Similar to `group`, but as an attribute filter.""" 265 270 attr_getter = make_attrgetter(_eval_ctx.environment, attr)
comment:5 by , 3 years ago
Release Notes: | modified (diff) |
---|---|
Resolution: | → fixed |
Status: | new → closed |
Thanks for the review! Pushed in [17591].
comment:6 by , 3 years ago
Owner: | set to |
---|
Note:
See TracTickets
for help on using tickets.
https://jinja.palletsprojects.com/en/3.1.x/changes/#version-3-1-0