Move to using minijinja for filter expressions? #1499
chrisjsewell
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
There are a number of problems with the "Python filter strings" currently used, but mainly I want to focus on undefined and nulled values.
When evaluating a Python expression, if any variables are not in the context, then it will fail with a
NameError
,or if you want to do a test on a "nullable" value, like
"a" in None
, then this will fail with aTypeError
This is a problem:
extra_options
when really most of these fields are only applicable to one or a few need typesWith https://pypi.org/project/minijinja/ you get sane handling of undefined and nullable values, with still a lot of builtin filters and tests that should satisfy most use cases, for example:
See also https://mitsuhiko.github.io/minijinja-playground/
Obviously this could be quite back-breaking, but I feel it would be worth the effort
It is also important to note the context in which a filter string is used, which can have subtle differences:
needimport
; we are filtering on the data of an item within aneeds.json
, not necessarily the "fully resolved" need.need_global_options
predicates; we are filtering on an "incompletely resolved" needneedextend
; we are filtering on an "incompletely resolved" need and need graph, e.g. it could still have unresolved dynamic functions and the backlinks have not been computed.needtable
and other "analysis" directives; we are now filtering on the "fully resolved" need (and need graph).Beta Was this translation helpful? Give feedback.
All reactions