Improve logging of warnings from Jinja2 processing - #7384
Merged
Conversation
oliver-sanders
approved these changes
Jul 30, 2026
Member
|
Would be good to add a test (the branch is uncovered so could easily break), here's my attempt: diff --git a/tests/unit/parsec/test_fileparse.py b/tests/unit/parsec/test_fileparse.py
index d0190246a7..307b3205ba 100644
--- a/tests/unit/parsec/test_fileparse.py
+++ b/tests/unit/parsec/test_fileparse.py
@@ -15,6 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from contextlib import suppress
+import logging
import os
from pathlib import Path
import re
@@ -313,6 +314,31 @@ def test_read_and_proc_no_template_engine():
assert r == ['a=b', 'c=d', '']
+def test_read_and_proc_jinja2_warning(log_filter):
+ with NamedTemporaryFile() as tf:
+ tf.write((
+ '#!Jinja2\n'
+ r"{% set x = '\${HOME}/foo/bar' %}"
+ ).encode())
+ tf.flush()
+ read_and_proc(
+ fpath=tf.name,
+ template_vars=None,
+ viewcfg={
+ 'jinja2': True,
+ 'contin': False,
+ 'inline': False,
+ },
+ )
+ assert log_filter(
+ level=logging.WARNING,
+ contains=(
+ f'{tf.name}:<jinja2 template>:'
+ ' DeprecationWarning: invalid escape sequence'
+ ),
+ )
+
+
def test_inline():
with NamedTemporaryFile() as tf:
fpath = tf.name |
Member
Author
|
I'm a little hesitant to add a test with a limited shelf life that will break at some point in the future on a new Python version |
Member
|
That's just a starter using the example in the OP, can maybe swap out the Python deprecation for something like: {% from "warnings" import warn %}
{% do warn(...) %} |
Member
Author
|
If I do that, the warning comes from |
…arsing of Cylc config
oliver-sanders
approved these changes
Aug 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #7365
Changes the apparent source of some warnings raised during jinja2 processing from the jinja2 source code to the Cylc config file
Repro
Before
After
Check List
CONTRIBUTING.mdand added my name as a Code Contributor.?.?.xbranch.