-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
jinja2: move to version 3 #4702
Comments
Haha 🤣 |
8.0, in case there are breaking changes (which we know about or not) from the Jinja2 upgrade. |
Discussion: we will test against example workflows with advanced Jinja2 usage to check for any compatibility issues |
If it causes problems, we may need to resort to parallel installations of Cylc 8 for a while, one with old-Jinja2 for use with Cylc 7 back-compat mode. (Worst case scenario!). |
Have begun testing our workflows with Jinja2 v3, unfortunately one issue has show up very quickly, like Python Jinja2 now considers an integer with a leading zero to be a syntax error: # python 2
foo = 4 # fine
foo = 04 # octal
# jinja2 v2
foo = 4 # fine
foo = 04 # fine, integer presumably?
# python 3
foo = 4 # fine
foo = 04 # error
foo = o04 # octal
# jinja2 v3
foo = 4 # fine
foo = 04 # error
foo = o04 # octal presumably This issue is probably very widespread and has impacts to both |
Besides the occasional (and unavoidable Python 2->3 error) I'm also finding substantial diffs in the graph sections of complex workflows. It looks like subtle line order changes but would have to confirm that, strange that it's only in Graph sections (I'm using |
Damn it 😬 |
The good news is that the diffs I was seeing were the result of a random element in the workflow definition and not the Jinja2 upgrade. The bad news is that the leading-zero issue is widespread and quite annoying. We've been here before and quickly realised this was way too disruptive so put in logic to back-support this: With the Jinja2 upgrade this test now fails and the problem returns:
Since we have already made the decision to back-support Jinja2 native syntax for template variables in the Zero-padded integers would still be invalid if used within the Cylc workflow files: # flow.cylc
{% set FOO=01 %} # ERROR However, would continue to be supported in the # rose-suite.conf
[template variables]
FOO=01 # fine (same for Rose 2 same for Rose 2019) |
Update: have managed to work out a way to back support integers with leading zeros in Jinja2 for Cylc-Rose. This allows us to issue deprecation warnings to manage the transition. |
Update: Solution to support integers with leading zeros here - cylc/cylc-rose#140 |
Having tested jinja2 v3.0 (and cylc/cylc-rose#140) using
against ~60,000 source suites at the MO, we have found only ~200 suites that fail in jinja2 v3.0 but not v2.x. All of these are due to leading zeros in integers. There are no suites where there is any difference in output between v3.0 and v2.x. I think we should probably put a note in the 7-to-8 docs about zero-padded integers. Perhaps in https://cylc.github.io/cylc-doc/nightly/html/7-to-8/major-changes/python-2-3.html? Or we can add a Jinja2 page to the Major Changes dir, but there isn't that much to say, just that the error message you get from Jinja2 is not very clear and I think we ought to document that leading zeros are the culprit
|
Thanks @MetRonnie! We have a temporary solution to supporting zero-padded integers in the With no other issues to report I think we are safe to move ahead with this at Cylc 8.0.0 without threatening Cylc7/8 interoperability or posing a major adoption barrier 🎉. Replacing the "investigation" label with small (update "setup.cfg" and "conda-environment.yml") and "doc" (see #4702 (comment)). |
Note we must move to Jinja2 Moving to Note we will want to advise users who wish to maintain Cylc 7 interoperability not to take action on Jinja2 warnings until then. |
Jinja2 has made it out of the 2.x series into the 3.x series (but is still called Jinja2).
Historically we have had to pin cylc-flow to exact versions of Jinja2 due to a series of highly disruptive breaking changes made during the 2.x series in order to give our users a fighting chance.
We should consider moving to version 3, however, do so cautiously. Suggest rendering a particularly complex workflow configuration with Jinja2 2.11 then with 3.? and comparing the output for piece of mind.
Questions:
Pull requests welcome!
The text was updated successfully, but these errors were encountered: