Conversation
…values construct_static_kwarg_value unconditionally stringified all config values, causing type mismatches (str vs list/dict) in unrendered_config comparisons across different dbt versions, leading to false positives in state:modified. Add _try_evaluate_to_python helper that preserves native Python types for Const, List, Dict, Tuple, and Neg AST nodes, falling back to string representation for complex nodes (Call, Name, etc.). Fixes dbt-labs#16133
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.
Resolves #16133
Problem
construct_static_kwarg_valueincore/dbt/clients/jinja_static.pyis typed-> strand unconditionally stringifies all config values parsed from Jinja{{ config(...) }}calls. This means literal lists and dicts like{{ config(cluster_by=['id']) }}produceunrendered_config['cluster_by'] == "['id']"(a string) instead of the native['id'](a list).When
upgrade_manifest_json_dbt_versionre-derivesunrendered_configfromraw_codefor a manifest with a differentdbt_version, the stringified values overwrite native types via.update(). Sincesame_config/same_contentscompareunrendered_configvalues with plain==, this type mismatch causesstate:modifiedto falsely flag models as changed — even when the SQL is identical.This affects any model with a list/dict-valued config key declared inline (
cluster_by,partition_by,grants,labels,meta,unique_keyas a list, etc.) wheneverstate:modifiedcompares manifests across different dbt versions.Solution
Added a
_try_evaluate_to_pythonhelper that recursively converts Jinja AST nodes to native Python values where possible:Const→ native value (str,int,float,bool,None)List→ Pythonlist(items evaluated recursively)Dict→ Pythondict(keys and values evaluated recursively)Tuple→ PythontupleNeg→ negated numeric value_reconstruct_node(same as before)Updated
construct_static_kwarg_valueto use this helper and changed its return type from-> strto-> Any. This ensures both the fresh-parse path and the upgrade path produce the same native types for literal config values, eliminating the type mismatch.No changes were needed to
_reconstruct_node,upgrade_unrendered_config, or the comparison logic insame_config/same_contents.Checklist