fix: three bugs in Jinja templater Python bridge#2587
Open
plasorak-nr wants to merge 2 commits into
Open
Conversation
added 2 commits
May 1, 2026 17:17
…ating in process_from_rust Two bugs fixed: 1. python_shared.rs: jinja_loader_search_path was serialised as Option<String> (null or a single string) but the Python FluffConfig NamedTuple declared it as List[str], causing a TypeError when fluff_config_from_json constructed the NamedTuple. Changed the Rust struct field to Vec<String> and updated the From<&FluffConfig> impl to collect the config value into a vec (handling both single-string and array config values). Updated the unit test assertion accordingly. 2. jinja_templater.py: process_from_rust raised ValueError whenever the templater returned any errors, even when the user had configured ignore_templating = true. Added a check against config.jinja_ignore_templating so templating warnings are suppressed when that flag is set.
jinja_templater.py passes line_no and line_pos keyword arguments when constructing SQLTemplaterError, but the class only accepted message, causing a TypeError at runtime. Added optional line_no and line_pos parameters (matching the signature used at the call site).
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.
Summary
This PR fixes three bugs in the Python Jinja templater that cause runtime errors when using loader_search_path or ignore_templating with the Jinja templater.
Fixes
jinja_loader_search_path type mismatch between Rust and Python (python_shared.rs)
The PythonFluffConfig Rust struct serialised jinja_loader_search_path as Option (i.e. null or a bare JSON string). However, the Python FluffConfig NamedTuple declares the field as List[str], so deserialisation via FluffConfig(**json.loads(...)) raised a TypeError at runtime whenever a loader_search_path was configured.
Fix: Changed the Rust field to Vec and updated the From<&FluffConfig> conversion to collect the config value into a vec, handling both single-string and array config values gracefully. Updated the unit test assertion accordingly.
process_from_rust raises ValueError even when ignore_templating = true (jinja_templater.py)
process_from_rust raised ValueError unconditionally whenever the templater returned any errors, ignoring the user's ignore_templating configuration. This made it impossible to lint Jinja templates that produce templating warnings (e.g. undefined variables used inside conditional blocks) even when the user had explicitly opted in to ignoring such warnings.
Fix: Added a check against config.jinja_ignore_templating before raising, so templating errors are only fatal when the user has not configured them to be ignored.
SQLTemplaterError does not accept line_no / line_pos (python_templater.py)
jinja_templater.py constructs SQLTemplaterError with line_no=1, line_pos=1 arguments, but
SQLTemplaterError.__init__only accepted message, causing aTypeError.Fix: Added optional line_no and line_pos parameters to
SQLTemplaterError.__init__.