You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In order to determine if the context should be passed to a function or filter, Jinja has the contextfunction and contextfilter decorators which set corresponding attributes on the functions. However, they're checked with if getattr(f, "contextfunction", 0), which causes issues for objects that are callable and have permissive __getattr__ functions, such as Mock.
Changing everything to default to False and check is True, would be good for consistency.
The full list is contextfunction, evalcontextfunction, environmentfunction, contextfilter, evalcontextfilter, and environmentcontextfilter.
Explicit checks for "is True" prevents unexpected behaviour with objects
that are callable and have permissive gettatr(), such as Mock.
Fixespallets#1145
I'm honestly not sure if it's a good idea to pass mock objects to a template in the first place. FWIW the reason 0 is used is because this code was faster on 2.x where the constant optimization was not applied yet.
I agree it's not, but there was another example of it coming up outside testing and it's a straightforward fix. 0 was only used in one place, False was used everywhere else already.
davidism
pushed a commit
to nicki-krizek/jinja
that referenced
this issue
Feb 4, 2020
Explicit checks for "is True" prevents unexpected behaviour with objects
that are callable and have permissive gettatr(), such as Mock.
Fixespallets#1145
In order to determine if the context should be passed to a function or filter, Jinja has the
contextfunction
andcontextfilter
decorators which set corresponding attributes on the functions. However, they're checked withif getattr(f, "contextfunction", 0)
, which causes issues for objects that are callable and have permissive__getattr__
functions, such asMock
.Changing everything to default to
False
and checkis True
, would be good for consistency.The full list is
contextfunction
,evalcontextfunction
,environmentfunction
,contextfilter
,evalcontextfilter
, andenvironmentcontextfilter
.Extracted from #1139
The text was updated successfully, but these errors were encountered: