diff --git a/.changes/1.9.0/Features-20240729-173203.yaml b/.changes/1.9.0/Features-20240729-173203.yaml deleted file mode 100644 index e788c8e9cc9..00000000000 --- a/.changes/1.9.0/Features-20240729-173203.yaml +++ /dev/null @@ -1,7 +0,0 @@ -kind: Features -body: Include models that depend on changed vars in state:modified, add state:modified.vars - selection method -time: 2024-07-29T17:32:03.368508-04:00 -custom: - Author: michelleark - Issue: "4304" diff --git a/core/dbt/artifacts/resources/v1/components.py b/core/dbt/artifacts/resources/v1/components.py index 02bfa5d875d..8eb43f35d8e 100644 --- a/core/dbt/artifacts/resources/v1/components.py +++ b/core/dbt/artifacts/resources/v1/components.py @@ -197,7 +197,6 @@ class ParsedResource(ParsedResourceMandatory): unrendered_config_call_dict: Dict[str, Any] = field(default_factory=dict) relation_name: Optional[str] = None raw_code: str = "" - vars: Dict[str, Any] = field(default_factory=dict) def __post_serialize__(self, dct: Dict, context: Optional[Dict] = None): dct = super().__post_serialize__(dct, context) diff --git a/core/dbt/artifacts/resources/v1/exposure.py b/core/dbt/artifacts/resources/v1/exposure.py index 7d8c291381b..00f3c8b89e1 100644 --- a/core/dbt/artifacts/resources/v1/exposure.py +++ b/core/dbt/artifacts/resources/v1/exposure.py @@ -41,7 +41,6 @@ class Exposure(GraphResource): tags: List[str] = field(default_factory=list) config: ExposureConfig = field(default_factory=ExposureConfig) unrendered_config: Dict[str, Any] = field(default_factory=dict) - vars: Dict[str, Any] = field(default_factory=dict) url: Optional[str] = None depends_on: DependsOn = field(default_factory=DependsOn) refs: List[RefArgs] = field(default_factory=list) diff --git a/core/dbt/artifacts/resources/v1/source_definition.py b/core/dbt/artifacts/resources/v1/source_definition.py index 454de4d7506..9044307563e 100644 --- a/core/dbt/artifacts/resources/v1/source_definition.py +++ b/core/dbt/artifacts/resources/v1/source_definition.py @@ -69,7 +69,6 @@ class SourceDefinition(ParsedSourceMandatory): config: SourceConfig = field(default_factory=SourceConfig) patch_path: Optional[str] = None unrendered_config: Dict[str, Any] = field(default_factory=dict) - vars: Dict[str, Any] = field(default_factory=dict) relation_name: Optional[str] = None created_at: float = field(default_factory=lambda: time.time()) unrendered_database: Optional[str] = None diff --git a/core/dbt/context/configured.py b/core/dbt/context/configured.py index 9ee7ebc79c3..240d9afb843 100644 --- a/core/dbt/context/configured.py +++ b/core/dbt/context/configured.py @@ -31,35 +31,23 @@ def __init__(self, package_name: str): self.resource_type = NodeType.Model -class SchemaYamlVars: - def __init__(self): - self.env_vars = {} - self.vars = {} - - class ConfiguredVar(Var): def __init__( self, context: Dict[str, Any], config: AdapterRequiredConfig, project_name: str, - schema_yaml_vars: Optional[SchemaYamlVars] = None, ): super().__init__(context, config.cli_vars) self._config = config self._project_name = project_name - self.schema_yaml_vars = schema_yaml_vars def __call__(self, var_name, default=Var._VAR_NOTSET): my_config = self._config.load_dependencies()[self._project_name] - var_found = False - var_value = None - # cli vars > active project > local project if var_name in self._config.cli_vars: - var_found = True - var_value = self._config.cli_vars[var_name] + return self._config.cli_vars[var_name] adapter_type = self._config.credentials.type lookup = FQNLookup(self._project_name) @@ -70,21 +58,19 @@ def __call__(self, var_name, default=Var._VAR_NOTSET): all_vars.add(my_config.vars.vars_for(lookup, adapter_type)) all_vars.add(active_vars) - if not var_found and var_name in all_vars: - var_found = True - var_value = all_vars[var_name] + if var_name in all_vars: + return all_vars[var_name] - if not var_found and default is not Var._VAR_NOTSET: - var_found = True - var_value = default + if default is not Var._VAR_NOTSET: + return default - if not var_found: - return self.get_missing_var(var_name) - else: - if self.schema_yaml_vars: - self.schema_yaml_vars.vars[var_name] = var_value + return self.get_missing_var(var_name) - return var_value + +class SchemaYamlVars: + def __init__(self): + self.env_vars = {} + self.vars = {} class SchemaYamlContext(ConfiguredContext): @@ -96,7 +82,7 @@ def __init__(self, config, project_name: str, schema_yaml_vars: Optional[SchemaY @contextproperty() def var(self) -> ConfiguredVar: - return ConfiguredVar(self._ctx, self.config, self._project_name, self.schema_yaml_vars) + return ConfiguredVar(self._ctx, self.config, self._project_name) @contextmember() def env_var(self, var: str, default: Optional[str] = None) -> str: diff --git a/core/dbt/context/providers.py b/core/dbt/context/providers.py index a0e3751587a..dfc8c9bb40b 100644 --- a/core/dbt/context/providers.py +++ b/core/dbt/context/providers.py @@ -790,14 +790,6 @@ def get_missing_var(self, var_name): # in the parser, just always return None. return None - def __call__(self, var_name: str, default: Any = ModelConfiguredVar._VAR_NOTSET) -> Any: - var_value = super().__call__(var_name, default) - - if self._node and hasattr(self._node, "vars"): - self._node.vars[var_name] = var_value - - return var_value - class RuntimeVar(ModelConfiguredVar): pass diff --git a/core/dbt/contracts/files.py b/core/dbt/contracts/files.py index a1cc75abcc4..d5c1dba5366 100644 --- a/core/dbt/contracts/files.py +++ b/core/dbt/contracts/files.py @@ -215,7 +215,6 @@ class SchemaSourceFile(BaseSourceFile): unrendered_configs: Dict[str, Any] = field(default_factory=dict) unrendered_databases: Dict[str, Any] = field(default_factory=dict) unrendered_schemas: Dict[str, Any] = field(default_factory=dict) - vars: Dict[str, Any] = field(default_factory=dict) pp_dict: Optional[Dict[str, Any]] = None pp_test_index: Optional[Dict[str, Any]] = None @@ -356,22 +355,6 @@ def delete_from_unrendered_configs(self, yaml_key, name): if not self.unrendered_configs[yaml_key]: del self.unrendered_configs[yaml_key] - def add_vars(self, vars: Dict[str, Any], yaml_key: str, name: str) -> None: - if yaml_key not in self.vars: - self.vars[yaml_key] = {} - - if name not in self.vars[yaml_key]: - self.vars[yaml_key][name] = vars - - def get_vars(self, yaml_key: str, name: str) -> Dict[str, Any]: - if yaml_key not in self.vars: - return {} - - if name not in self.vars[yaml_key]: - return {} - - return self.vars[yaml_key][name] - def add_env_var(self, var, yaml_key, name): if yaml_key not in self.env_vars: self.env_vars[yaml_key] = {} diff --git a/core/dbt/contracts/graph/nodes.py b/core/dbt/contracts/graph/nodes.py index f50eb1d9641..2d9ff77b385 100644 --- a/core/dbt/contracts/graph/nodes.py +++ b/core/dbt/contracts/graph/nodes.py @@ -369,9 +369,6 @@ def same_contract(self, old, adapter_type=None) -> bool: # This would only apply to seeds return True - def same_vars(self, old) -> bool: - return self.vars == old.vars - def same_contents(self, old, adapter_type) -> bool: if old is None: return False @@ -379,20 +376,12 @@ def same_contents(self, old, adapter_type) -> bool: # Need to ensure that same_contract is called because it # could throw an error same_contract = self.same_contract(old, adapter_type) - - # Legacy behaviour - if not get_flags().state_modified_compare_vars: - same_vars = True - else: - same_vars = self.same_vars(old) - return ( self.same_body(old) and self.same_config(old) and self.same_persisted_description(old) and self.same_fqn(old) and self.same_database_representation(old) - and same_vars and same_contract and True ) @@ -1266,9 +1255,6 @@ def same_config(self, old: "SourceDefinition") -> bool: old.unrendered_config, ) - def same_vars(self, other: "SourceDefinition") -> bool: - return self.vars == other.vars - def same_contents(self, old: Optional["SourceDefinition"]) -> bool: # existing when it didn't before is a change! if old is None: @@ -1282,12 +1268,6 @@ def same_contents(self, old: Optional["SourceDefinition"]) -> bool: # freshness changes are changes, I guess # metadata/tags changes are not "changes" # patching/description changes are not "changes" - # Legacy behaviour - if not get_flags().state_modified_compare_vars: - same_vars = True - else: - same_vars = self.same_vars(old) - return ( self.same_database_representation(old) and self.same_fqn(old) @@ -1295,7 +1275,6 @@ def same_contents(self, old: Optional["SourceDefinition"]) -> bool: and self.same_quoting(old) and self.same_freshness(old) and self.same_external(old) - and same_vars and True ) @@ -1392,21 +1371,12 @@ def same_config(self, old: "Exposure") -> bool: old.unrendered_config, ) - def same_vars(self, old: "Exposure") -> bool: - return self.vars == old.vars - def same_contents(self, old: Optional["Exposure"]) -> bool: # existing when it didn't before is a change! # metadata/tags changes are not "changes" if old is None: return True - # Legacy behaviour - if not get_flags().state_modified_compare_vars: - same_vars = True - else: - same_vars = self.same_vars(old) - return ( self.same_fqn(old) and self.same_exposure_type(old) @@ -1417,7 +1387,6 @@ def same_contents(self, old: Optional["Exposure"]) -> bool: and self.same_label(old) and self.same_depends_on(old) and self.same_config(old) - and same_vars and True ) @@ -1669,7 +1638,6 @@ class ParsedNodePatch(ParsedPatch): latest_version: Optional[NodeVersion] constraints: List[Dict[str, Any]] deprecation_date: Optional[datetime] - vars: Dict[str, Any] time_spine: Optional[TimeSpine] = None diff --git a/core/dbt/graph/selector_methods.py b/core/dbt/graph/selector_methods.py index c7a2490760b..dbeaf7ed4c3 100644 --- a/core/dbt/graph/selector_methods.py +++ b/core/dbt/graph/selector_methods.py @@ -752,7 +752,6 @@ def search(self, included_nodes: Set[UniqueId], selector: str) -> Iterator[Uniqu "modified.relation": self.check_modified_factory("same_database_representation"), "modified.macros": self.check_modified_macros, "modified.contract": self.check_modified_contract("same_contract", adapter_type), - "modified.vars": self.check_modified_factory("same_vars"), } if selector in state_checks: checker = state_checks[selector] diff --git a/core/dbt/parser/schema_yaml_readers.py b/core/dbt/parser/schema_yaml_readers.py index 4fe28a74866..dc99e87a218 100644 --- a/core/dbt/parser/schema_yaml_readers.py +++ b/core/dbt/parser/schema_yaml_readers.py @@ -91,9 +91,6 @@ def parse_exposure(self, unparsed: UnparsedExposure) -> None: unique_id = f"{NodeType.Exposure}.{package_name}.{unparsed.name}" path = self.yaml.path.relative_path - assert isinstance(self.yaml.file, SchemaSourceFile) - exposure_vars = self.yaml.file.get_vars(self.key, unparsed.name) - fqn = self.schema_parser.get_fqn_prefix(path) fqn.append(unparsed.name) @@ -136,7 +133,6 @@ def parse_exposure(self, unparsed: UnparsedExposure) -> None: maturity=unparsed.maturity, config=config, unrendered_config=unrendered_config, - vars=exposure_vars, ) ctx = generate_parse_exposure( parsed, @@ -148,6 +144,7 @@ def parse_exposure(self, unparsed: UnparsedExposure) -> None: get_rendered(depends_on_jinja, ctx, parsed, capture_macros=True) # parsed now has a populated refs/sources/metrics + assert isinstance(self.yaml.file, SchemaSourceFile) if parsed.config.enabled: self.manifest.add_exposure(self.yaml.file, parsed) else: diff --git a/core/dbt/parser/schemas.py b/core/dbt/parser/schemas.py index 727f4bcf676..077d7083ed5 100644 --- a/core/dbt/parser/schemas.py +++ b/core/dbt/parser/schemas.py @@ -431,14 +431,10 @@ def get_key_dicts(self) -> Iterable[Dict[str, Any]]: if self.schema_yaml_vars.env_vars: self.schema_parser.manifest.env_vars.update(self.schema_yaml_vars.env_vars) - for env_var in self.schema_yaml_vars.env_vars.keys(): - schema_file.add_env_var(env_var, self.key, entry["name"]) + for var in self.schema_yaml_vars.env_vars.keys(): + schema_file.add_env_var(var, self.key, entry["name"]) self.schema_yaml_vars.env_vars = {} - if self.schema_yaml_vars.vars: - schema_file.add_vars(self.schema_yaml_vars.vars, self.key, entry["name"]) - self.schema_yaml_vars.vars = {} - yield entry def render_entry(self, dct): @@ -718,9 +714,6 @@ def parse_patch(self, block: TargetBlock[NodeTarget], refs: ParserRef) -> None: # code consistency. deprecation_date: Optional[datetime.datetime] = None time_spine: Optional[TimeSpine] = None - assert isinstance(self.yaml.file, SchemaSourceFile) - source_file: SchemaSourceFile = self.yaml.file - if isinstance(block.target, UnparsedModelUpdate): deprecation_date = block.target.deprecation_date time_spine = ( @@ -753,9 +746,9 @@ def parse_patch(self, block: TargetBlock[NodeTarget], refs: ParserRef) -> None: constraints=block.target.constraints, deprecation_date=deprecation_date, time_spine=time_spine, - vars=source_file.get_vars(block.target.yaml_key, block.target.name), ) - + assert isinstance(self.yaml.file, SchemaSourceFile) + source_file: SchemaSourceFile = self.yaml.file if patch.yaml_key in ["models", "seeds", "snapshots"]: unique_id = self.manifest.ref_lookup.get_unique_id( patch.name, self.project.project_name, None @@ -849,8 +842,6 @@ def patch_node_properties(self, node, patch: "ParsedNodePatch") -> None: node.description = patch.description node.columns = patch.columns node.name = patch.name - # Prefer node-level vars to vars from patch - node.vars = {**patch.vars, **node.vars} if not isinstance(node, ModelNode): for attr in ["latest_version", "access", "version", "constraints"]: @@ -1000,7 +991,6 @@ def parse_patch(self, block: TargetBlock[UnparsedModelUpdate], refs: ParserRef) latest_version=latest_version, constraints=unparsed_version.constraints or target.constraints, deprecation_date=unparsed_version.deprecation_date, - vars=source_file.get_vars(block.target.yaml_key, block.target.name), ) # Node patched before config because config patching depends on model name, # which may have been updated in the version patch diff --git a/core/dbt/parser/sources.py b/core/dbt/parser/sources.py index e98b3103691..0fe882750ae 100644 --- a/core/dbt/parser/sources.py +++ b/core/dbt/parser/sources.py @@ -12,7 +12,6 @@ ContextConfigGenerator, UnrenderedConfigGenerator, ) -from dbt.contracts.files import SchemaSourceFile from dbt.contracts.graph.manifest import Manifest, SourceKey from dbt.contracts.graph.nodes import ( GenericTestNode, @@ -159,10 +158,6 @@ def parse_source(self, target: UnpatchedSourceDefinition) -> SourceDefinition: rendered=False, ) - schema_file = self.manifest.files[target.file_id] - assert isinstance(schema_file, SchemaSourceFile) - source_vars = schema_file.get_vars("sources", source.name) - if not isinstance(config, SourceConfig): raise DbtInternalError( f"Calculated a {type(config)} for a source, but expected a SourceConfig" @@ -197,7 +192,6 @@ def parse_source(self, target: UnpatchedSourceDefinition) -> SourceDefinition: tags=tags, config=config, unrendered_config=unrendered_config, - vars=source_vars, ) if ( diff --git a/schemas/dbt/manifest/v12.json b/schemas/dbt/manifest/v12.json index c58275fa35b..cecc35c58bb 100644 --- a/schemas/dbt/manifest/v12.json +++ b/schemas/dbt/manifest/v12.json @@ -706,12 +706,6 @@ "type": "string" } }, - "unrendered_config_call_dict": { - "type": "object", - "propertyNames": { - "type": "string" - } - }, "relation_name": { "anyOf": [ { @@ -727,12 +721,6 @@ "type": "string", "default": "" }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } - }, "root_path": { "anyOf": [ { @@ -1751,12 +1739,6 @@ "type": "string" } }, - "unrendered_config_call_dict": { - "type": "object", - "propertyNames": { - "type": "string" - } - }, "relation_name": { "anyOf": [ { @@ -1772,12 +1754,6 @@ "type": "string", "default": "" }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } - }, "language": { "type": "string", "default": "sql" @@ -2411,12 +2387,6 @@ "type": "string" } }, - "unrendered_config_call_dict": { - "type": "object", - "propertyNames": { - "type": "string" - } - }, "relation_name": { "anyOf": [ { @@ -2432,12 +2402,6 @@ "type": "string", "default": "" }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } - }, "language": { "type": "string", "default": "sql" @@ -3208,12 +3172,6 @@ "type": "string" } }, - "unrendered_config_call_dict": { - "type": "object", - "propertyNames": { - "type": "string" - } - }, "relation_name": { "anyOf": [ { @@ -3229,12 +3187,6 @@ "type": "string", "default": "" }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } - }, "language": { "type": "string", "default": "sql" @@ -4024,12 +3976,6 @@ "type": "string" } }, - "unrendered_config_call_dict": { - "type": "object", - "propertyNames": { - "type": "string" - } - }, "relation_name": { "anyOf": [ { @@ -4045,12 +3991,6 @@ "type": "string", "default": "" }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } - }, "language": { "type": "string", "default": "sql" @@ -5391,12 +5331,6 @@ "type": "string" } }, - "unrendered_config_call_dict": { - "type": "object", - "propertyNames": { - "type": "string" - } - }, "relation_name": { "anyOf": [ { @@ -5412,12 +5346,6 @@ "type": "string", "default": "" }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } - }, "language": { "type": "string", "default": "sql" @@ -6051,12 +5979,6 @@ "type": "string" } }, - "unrendered_config_call_dict": { - "type": "object", - "propertyNames": { - "type": "string" - } - }, "relation_name": { "anyOf": [ { @@ -6072,12 +5994,6 @@ "type": "string", "default": "" }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } - }, "language": { "type": "string", "default": "sql" @@ -7015,12 +6931,6 @@ "type": "string" } }, - "unrendered_config_call_dict": { - "type": "object", - "propertyNames": { - "type": "string" - } - }, "relation_name": { "anyOf": [ { @@ -7036,12 +6946,6 @@ "type": "string", "default": "" }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } - }, "language": { "type": "string", "default": "sql" @@ -8179,12 +8083,6 @@ "type": "string" } }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } - }, "relation_name": { "anyOf": [ { @@ -8578,12 +8476,6 @@ "type": "string" } }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } - }, "url": { "anyOf": [ { @@ -10640,12 +10532,6 @@ "type": "string" } }, - "unrendered_config_call_dict": { - "type": "object", - "propertyNames": { - "type": "string" - } - }, "relation_name": { "anyOf": [ { @@ -10661,12 +10547,6 @@ "type": "string", "default": "" }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } - }, "root_path": { "anyOf": [ { @@ -11685,12 +11565,6 @@ "type": "string" } }, - "unrendered_config_call_dict": { - "type": "object", - "propertyNames": { - "type": "string" - } - }, "relation_name": { "anyOf": [ { @@ -11706,12 +11580,6 @@ "type": "string", "default": "" }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } - }, "language": { "type": "string", "default": "sql" @@ -12345,12 +12213,6 @@ "type": "string" } }, - "unrendered_config_call_dict": { - "type": "object", - "propertyNames": { - "type": "string" - } - }, "relation_name": { "anyOf": [ { @@ -12366,12 +12228,6 @@ "type": "string", "default": "" }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } - }, "language": { "type": "string", "default": "sql" @@ -13142,12 +12998,6 @@ "type": "string" } }, - "unrendered_config_call_dict": { - "type": "object", - "propertyNames": { - "type": "string" - } - }, "relation_name": { "anyOf": [ { @@ -13163,12 +13013,6 @@ "type": "string", "default": "" }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } - }, "language": { "type": "string", "default": "sql" @@ -13958,12 +13802,6 @@ "type": "string" } }, - "unrendered_config_call_dict": { - "type": "object", - "propertyNames": { - "type": "string" - } - }, "relation_name": { "anyOf": [ { @@ -13979,12 +13817,6 @@ "type": "string", "default": "" }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } - }, "language": { "type": "string", "default": "sql" @@ -15325,12 +15157,6 @@ "type": "string" } }, - "unrendered_config_call_dict": { - "type": "object", - "propertyNames": { - "type": "string" - } - }, "relation_name": { "anyOf": [ { @@ -15346,12 +15172,6 @@ "type": "string", "default": "" }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } - }, "language": { "type": "string", "default": "sql" @@ -15985,12 +15805,6 @@ "type": "string" } }, - "unrendered_config_call_dict": { - "type": "object", - "propertyNames": { - "type": "string" - } - }, "relation_name": { "anyOf": [ { @@ -16006,12 +15820,6 @@ "type": "string", "default": "" }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } - }, "language": { "type": "string", "default": "sql" @@ -16949,12 +16757,6 @@ "type": "string" } }, - "unrendered_config_call_dict": { - "type": "object", - "propertyNames": { - "type": "string" - } - }, "relation_name": { "anyOf": [ { @@ -16970,12 +16772,6 @@ "type": "string", "default": "" }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } - }, "language": { "type": "string", "default": "sql" @@ -18104,12 +17900,6 @@ "type": "string" } }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } - }, "relation_name": { "anyOf": [ { @@ -18301,12 +18091,6 @@ "type": "string" } }, - "vars": { - "type": "object", - "propertyNames": { - "type": "string" - } - }, "url": { "anyOf": [ { diff --git a/tests/functional/artifacts/expected_manifest.py b/tests/functional/artifacts/expected_manifest.py index 05317fa0df9..501efef85a2 100644 --- a/tests/functional/artifacts/expected_manifest.py +++ b/tests/functional/artifacts/expected_manifest.py @@ -363,7 +363,6 @@ def expected_seeded_manifest(project, model_database=None, quote_model=False): "extra_ctes": [], "checksum": checksum_file(model_sql_path), "unrendered_config": unrendered_model_config, - "vars": {}, "access": "protected", "version": None, "latest_version": None, @@ -463,7 +462,6 @@ def expected_seeded_manifest(project, model_database=None, quote_model=False): "extra_ctes": [], "checksum": checksum_file(second_model_sql_path), "unrendered_config": unrendered_second_config, - "vars": {}, "access": "protected", "version": None, "latest_version": None, @@ -546,7 +544,6 @@ def expected_seeded_manifest(project, model_database=None, quote_model=False): "docs": {"node_color": None, "show": True}, "checksum": checksum_file(seed_path), "unrendered_config": unrendered_seed_config, - "vars": {}, "relation_name": relation_name_node_format.format( project.database, my_schema_name, "seed" ), @@ -602,7 +599,6 @@ def expected_seeded_manifest(project, model_database=None, quote_model=False): }, "checksum": {"name": "none", "checksum": ""}, "unrendered_config": unrendered_test_config, - "vars": {}, "contract": {"checksum": None, "enforced": False, "alias_types": True}, }, "snapshot.test.snapshot_seed": { @@ -650,7 +646,6 @@ def expected_seeded_manifest(project, model_database=None, quote_model=False): "tags": [], "unique_id": "snapshot.test.snapshot_seed", "unrendered_config": unrendered_snapshot_config, - "vars": {"alternate_schema": alternate_schema}, }, "test.test.test_nothing_model_.5d38568946": { "alias": "test_nothing_model_", @@ -703,7 +698,6 @@ def expected_seeded_manifest(project, model_database=None, quote_model=False): }, "checksum": {"name": "none", "checksum": ""}, "unrendered_config": unrendered_test_config, - "vars": {}, }, "test.test.unique_model_id.67b76558ff": { "alias": "unique_model_id", @@ -757,7 +751,6 @@ def expected_seeded_manifest(project, model_database=None, quote_model=False): }, "checksum": {"name": "none", "checksum": ""}, "unrendered_config": unrendered_test_config, - "vars": {}, }, }, "sources": { @@ -816,7 +809,6 @@ def expected_seeded_manifest(project, model_database=None, quote_model=False): "unrendered_config": {}, "unrendered_database": None, "unrendered_schema": "{{ var('test_schema') }}", - "vars": {"test_schema": ANY}, }, }, "exposures": { @@ -851,7 +843,6 @@ def expected_seeded_manifest(project, model_database=None, quote_model=False): "unique_id": "exposure.test.notebook_exposure", "url": "http://example.com/notebook/1", "unrendered_config": {}, - "vars": {}, }, "exposure.test.simple_exposure": { "created_at": ANY, @@ -884,7 +875,6 @@ def expected_seeded_manifest(project, model_database=None, quote_model=False): "meta": {}, "tags": [], "unrendered_config": {}, - "vars": {}, }, }, "metrics": {}, @@ -1002,7 +992,6 @@ def expected_references_manifest(project): "extra_ctes": [], "checksum": checksum_file(ephemeral_copy_path), "unrendered_config": get_unrendered_model_config(materialized="ephemeral"), - "vars": {}, "access": "protected", "version": None, "latest_version": None, @@ -1075,7 +1064,6 @@ def expected_references_manifest(project): "unrendered_config": get_unrendered_model_config( materialized="table", group="test_group" ), - "vars": {}, "access": "protected", "version": None, "latest_version": None, @@ -1144,7 +1132,6 @@ def expected_references_manifest(project): "extra_ctes": [], "checksum": checksum_file(view_summary_path), "unrendered_config": get_unrendered_model_config(materialized="view"), - "vars": {}, "access": "protected", "version": None, "latest_version": None, @@ -1228,7 +1215,6 @@ def expected_references_manifest(project): "unique_id": "seed.test.seed", "checksum": checksum_file(seed_path), "unrendered_config": get_unrendered_seed_config(), - "vars": {}, "relation_name": '"{0}"."{1}".seed'.format(project.database, my_schema_name), }, "snapshot.test.snapshot_seed": { @@ -1243,10 +1229,7 @@ def expected_references_manifest(project): "config": get_rendered_snapshot_config(target_schema=alternate_schema), "contract": {"checksum": None, "enforced": False, "alias_types": True}, "database": model_database, - "depends_on": { - "macros": [], - "nodes": ["seed.test.seed"], - }, + "depends_on": {"macros": [], "nodes": ["seed.test.seed"]}, "description": "", "docs": {"node_color": None, "show": True}, "extra_ctes": [], @@ -1274,7 +1257,6 @@ def expected_references_manifest(project): "unrendered_config": get_unrendered_snapshot_config( target_schema=alternate_schema ), - "vars": {"alternate_schema": alternate_schema}, }, }, "sources": { @@ -1331,7 +1313,6 @@ def expected_references_manifest(project): "unrendered_config": {}, "unrendered_database": None, "unrendered_schema": "{{ var('test_schema') }}", - "vars": {"test_schema": ANY}, }, }, "exposures": { @@ -1357,7 +1338,6 @@ def expected_references_manifest(project): "package_name": "test", "path": "schema.yml", "refs": [{"name": "view_summary", "package": None, "version": None}], - "vars": {}, "resource_type": "exposure", "sources": [], "type": "notebook", @@ -1618,7 +1598,6 @@ def expected_versions_manifest(project): group="test_group", meta={"size": "large", "color": "blue"}, ), - "vars": {}, "access": "protected", "version": 1, "latest_version": 2, @@ -1690,7 +1669,6 @@ def expected_versions_manifest(project): "unrendered_config": get_unrendered_model_config( materialized="view", group="test_group", meta={"size": "large", "color": "red"} ), - "vars": {}, "access": "protected", "version": 2, "latest_version": 2, @@ -1749,7 +1727,6 @@ def expected_versions_manifest(project): "extra_ctes": [], "checksum": checksum_file(ref_versioned_model_path), "unrendered_config": get_unrendered_model_config(), - "vars": {}, "access": "protected", "version": None, "latest_version": None, @@ -1807,7 +1784,6 @@ def expected_versions_manifest(project): }, "checksum": {"name": "none", "checksum": ""}, "unrendered_config": unrendered_test_config, - "vars": {}, }, "test.test.unique_versioned_model_v1_count.0b4c0b688a": { "alias": "unique_versioned_model_v1_count", @@ -1861,7 +1837,6 @@ def expected_versions_manifest(project): }, "checksum": {"name": "none", "checksum": ""}, "unrendered_config": unrendered_test_config, - "vars": {}, }, "test.test.unique_versioned_model_v2_first_name.998430d28e": { "alias": "unique_versioned_model_v2_first_name", @@ -1915,7 +1890,6 @@ def expected_versions_manifest(project): }, "checksum": {"name": "none", "checksum": ""}, "unrendered_config": unrendered_test_config, - "vars": {}, }, }, "exposures": { @@ -1947,7 +1921,6 @@ def expected_versions_manifest(project): "unique_id": "exposure.test.notebook_exposure", "url": None, "unrendered_config": {}, - "vars": {}, }, }, "metrics": {}, diff --git a/tests/functional/defer_state/test_modified_state.py b/tests/functional/defer_state/test_modified_state.py index 3d0f0955c93..2ded38e742b 100644 --- a/tests/functional/defer_state/test_modified_state.py +++ b/tests/functional/defer_state/test_modified_state.py @@ -1144,216 +1144,3 @@ def test_changed_semantic_model_contents(self, project): write_file(modified_semantic_model_schema_yml, "models", "schema.yml") results = run_dbt(["list", "-s", "state:modified", "--state", "./state"]) assert len(results) == 1 - - -class TestModifiedVarsLegacy(BaseModifiedState): - @pytest.fixture(scope="class") - def project_config_update(self): - return { - "flags": { - "state_modified_compare_vars": False, - }, - "vars": {"my_var": 1}, - } - - @pytest.fixture(scope="class") - def models(self): - return { - "model_with_var.sql": "select {{ var('my_var') }} as id", - } - - def test_changed_vars(self, project): - self.run_and_save_state() - - # No var change - assert not run_dbt(["list", "-s", "state:modified", "--state", "./state"]) - assert not run_dbt(["list", "-s", "state:modified.vars", "--state", "./state"]) - - # Modify var (my_var: 1 -> 2) - update_config_file({"vars": {"my_var": 2}}, "dbt_project.yml") - - # By default, do not detect vars in state:modified to preserve legacy behaviour - assert run_dbt(["list", "-s", "state:modified", "--state", "./state"]) == [] - - # state:modified.vars is a new selector, opt-in method -> returns results - assert run_dbt(["list", "-s", "state:modified.vars", "--state", "./state"]) == [ - "test.model_with_var" - ] - - # Reset dbt_project.yml - update_config_file({"vars": {"my_var": 1}}, "dbt_project.yml") - - # Modify var via --var CLI flag - assert not run_dbt( - ["list", "--vars", '{"my_var": 1}', "-s", "state:modified", "--state", "./state"] - ) - assert ( - run_dbt( - ["list", "--vars", '{"my_var": 2}', "-s", "state:modified", "--state", "./state"] - ) - == [] - ) - # state:modified.vars is a new selector, opt-in method -> returns results - assert run_dbt( - ["list", "--vars", '{"my_var": 2}', "-s", "state:modified.vars", "--state", "./state"] - ) == ["test.model_with_var"] - - -class TestModifiedVars(BaseModifiedState): - @pytest.fixture(scope="class") - def project_config_update(self): - return { - "flags": { - "state_modified_compare_vars": True, - }, - "vars": {"my_var": 1}, - } - - @pytest.fixture(scope="class") - def models(self): - return { - "model_with_var.sql": "select {{ var('my_var') }} as id", - } - - def test_changed_vars(self, project): - self.run_and_save_state() - - # No var change - assert not run_dbt(["list", "-s", "state:modified", "--state", "./state"]) - assert not run_dbt(["list", "-s", "state:modified.vars", "--state", "./state"]) - - # Modify var (my_var: 1 -> 2) - update_config_file({"vars": {"my_var": 2}}, "dbt_project.yml") - assert run_dbt(["list", "-s", "state:modified", "--state", "./state"]) == [ - "test.model_with_var" - ] - assert run_dbt(["list", "-s", "state:modified.vars", "--state", "./state"]) == [ - "test.model_with_var" - ] - - # Reset dbt_project.yml - update_config_file({"vars": {"my_var": 1}}, "dbt_project.yml") - - # Modify var via --var CLI flag - assert not run_dbt( - ["list", "--vars", '{"my_var": 1}', "-s", "state:modified", "--state", "./state"] - ) - assert run_dbt( - ["list", "--vars", '{"my_var": 2}', "-s", "state:modified", "--state", "./state"] - ) == ["test.model_with_var"] - - -macro_with_var_sql = """ -{% macro macro_with_var() %} - {{ var('my_var') }} -{% endmacro %} -""" - - -class TestModifiedMacroVars(BaseModifiedState): - @pytest.fixture(scope="class") - def project_config_update(self): - return { - "flags": { - "state_modified_compare_vars": True, - }, - "vars": {"my_var": 1}, - } - - @pytest.fixture(scope="class") - def models(self): - return { - "model_with_macro.sql": "select {{ macro_with_var() }} as id", - } - - @pytest.fixture(scope="class") - def macros(self): - return { - "macro_with_var.sql": macro_with_var_sql, - } - - def test_changed_vars(self, project): - self.run_and_save_state() - - # No var change - assert not run_dbt(["list", "-s", "state:modified", "--state", "./state"]) - assert not run_dbt(["list", "-s", "state:modified.vars", "--state", "./state"]) - - # Modify var (my_var: 1 -> 2) - update_config_file({"vars": {"my_var": 2}}, "dbt_project.yml") - assert run_dbt(["list", "-s", "state:modified", "--state", "./state"]) == [ - "test.model_with_macro" - ] - assert run_dbt(["list", "-s", "state:modified.vars", "--state", "./state"]) == [ - "test.model_with_macro" - ] - - # Macros themselves not captured as modified because the var value depends on a node's context - assert not run_dbt(["list", "-s", "state:modified.macros", "--state", "./state"]) - - -# TODO: test versioned models, tests -model_with_var_schema_yml = """ -version: 2 -models: - - name: model_with_var - config: - materialized: "{{ var('my_var') }}" - -exposures: - - name: exposure_name - type: dashboard - owner: - name: "{{ var('my_var') }}" - -sources: - - name: jaffle_shop - database: "{{ var('my_var') }}" - schema: jaffle_shop - tables: - - name: orders - - name: customers -""" - - -class TestModifiedVarsSchemaYml(BaseModifiedState): - @pytest.fixture(scope="class") - def project_config_update(self): - return { - "flags": { - "state_modified_compare_vars": True, - }, - "vars": {"my_var": "table"}, - } - - @pytest.fixture(scope="class") - def models(self): - return {"model_with_var.sql": "select 1 as id", "schema.yml": model_with_var_schema_yml} - - def test_changed_vars(self, project): - self.run_and_save_state() - - # No var change - assert not run_dbt(["list", "-s", "state:modified", "--state", "./state"]) - assert not run_dbt(["list", "-s", "state:modified.vars", "--state", "./state"]) - - # Modify var (my_var: table -> view) - update_config_file({"vars": {"my_var": "view"}}, "dbt_project.yml") - assert sorted(run_dbt(["list", "-s", "state:modified", "--state", "./state"])) == sorted( - [ - "test.model_with_var", - "exposure:test.exposure_name", - "source:test.jaffle_shop.customers", - "source:test.jaffle_shop.orders", - ] - ) - assert sorted( - run_dbt(["list", "-s", "state:modified.vars", "--state", "./state"]) - ) == sorted( - [ - "test.model_with_var", - "exposure:test.exposure_name", - "source:test.jaffle_shop.customers", - "source:test.jaffle_shop.orders", - ] - ) diff --git a/tests/functional/list/test_list.py b/tests/functional/list/test_list.py index 7b98e5c8251..6894ec96bb4 100644 --- a/tests/functional/list/test_list.py +++ b/tests/functional/list/test_list.py @@ -49,10 +49,7 @@ def expect_snapshot_output(self, happy_path_project): # noqa: F811 "json": { "name": "my_snapshot", "package_name": "test", - "depends_on": { - "nodes": [], - "macros": [], - }, + "depends_on": {"nodes": [], "macros": []}, "tags": [], "config": { "enabled": True, diff --git a/tests/unit/contracts/graph/test_manifest.py b/tests/unit/contracts/graph/test_manifest.py index 68676e2298e..146a51d5856 100644 --- a/tests/unit/contracts/graph/test_manifest.py +++ b/tests/unit/contracts/graph/test_manifest.py @@ -97,7 +97,6 @@ "defer_relation", "time_spine", "batch_info", - "vars", } ) diff --git a/tests/unit/contracts/graph/test_nodes.py b/tests/unit/contracts/graph/test_nodes.py index 1271cb7108f..061c1cdcdea 100644 --- a/tests/unit/contracts/graph/test_nodes.py +++ b/tests/unit/contracts/graph/test_nodes.py @@ -206,7 +206,6 @@ def basic_compiled_dict(): }, "unrendered_config": {}, "unrendered_config_call_dict": {}, - "vars": {}, "config_call_dict": {}, "access": "protected", "constraints": [], @@ -527,7 +526,6 @@ def basic_compiled_schema_test_dict(): "severity": "warn", }, "unrendered_config_call_dict": {}, - "vars": {}, "config_call_dict": {}, } diff --git a/tests/unit/contracts/graph/test_nodes_parsed.py b/tests/unit/contracts/graph/test_nodes_parsed.py index db0b6fae653..7ac7b307235 100644 --- a/tests/unit/contracts/graph/test_nodes_parsed.py +++ b/tests/unit/contracts/graph/test_nodes_parsed.py @@ -204,7 +204,6 @@ def base_parsed_model_dict(): }, "unrendered_config": {}, "unrendered_config_call_dict": {}, - "vars": {}, "config_call_dict": {}, "access": AccessType.Protected.value, "constraints": [], @@ -261,7 +260,6 @@ def minimal_parsed_model_dict(): "checksum": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", }, "unrendered_config": {}, - "vars": {}, } @@ -329,7 +327,6 @@ def complex_parsed_model_dict(): "post_hook": ['insert into blah(a, b) select "1", 1'], }, "unrendered_config_call_dict": {}, - "vars": {}, "config_call_dict": {}, "access": AccessType.Protected.value, "constraints": [], @@ -540,7 +537,6 @@ def basic_parsed_seed_dict(): "checksum": {"name": "path", "checksum": "seeds/seed.csv"}, "unrendered_config": {}, "unrendered_config_call_dict": {}, - "vars": {}, "config_call_dict": {}, } @@ -647,7 +643,6 @@ def complex_parsed_seed_dict(): "persist_docs": {"relation": True, "columns": True}, }, "unrendered_config_call_dict": {}, - "vars": {}, "config_call_dict": {}, } @@ -848,7 +843,6 @@ def base_parsed_hook_dict(): }, "unrendered_config": {}, "unrendered_config_call_dict": {}, - "vars": {}, "config_call_dict": {}, } @@ -943,7 +937,6 @@ def complex_parsed_hook_dict(): "materialized": "table", }, "unrendered_config_call_dict": {}, - "vars": {}, "config_call_dict": {}, } @@ -1089,7 +1082,6 @@ def basic_parsed_schema_test_dict(): }, "unrendered_config": {}, "unrendered_config_call_dict": {}, - "vars": {}, "config_call_dict": {}, } @@ -1179,7 +1171,6 @@ def complex_parsed_schema_test_dict(): }, "unrendered_config": {"materialized": "table", "severity": "WARN"}, "unrendered_config_call_dict": {}, - "vars": {}, "config_call_dict": {}, } @@ -1575,7 +1566,6 @@ def basic_timestamp_snapshot_dict(): "target_schema": "some_snapshot_schema", }, "unrendered_config_call_dict": {}, - "vars": {}, "config_call_dict": {}, } @@ -1682,7 +1672,6 @@ def basic_check_snapshot_dict(): }, "unrendered_config_call_dict": {}, "config_call_dict": {}, - "vars": {}, } @@ -1892,7 +1881,6 @@ def basic_parsed_source_definition_dict(): "enabled": True, }, "unrendered_config": {}, - "vars": {}, } @@ -1925,7 +1913,6 @@ def complex_parsed_source_definition_dict(): "freshness": {"warn_after": {"period": "hour", "count": 1}, "error_after": {}}, "loaded_at_field": "loaded_at", "unrendered_config": {}, - "vars": {}, } @@ -2097,7 +2084,6 @@ def basic_parsed_exposure_dict(): "enabled": True, }, "unrendered_config": {}, - "vars": {}, } @@ -2153,7 +2139,6 @@ def complex_parsed_exposure_dict(): "enabled": True, }, "unrendered_config": {}, - "vars": {}, } diff --git a/tests/unit/parser/test_parser.py b/tests/unit/parser/test_parser.py index 0d95a495cdf..b9b414ebac2 100644 --- a/tests/unit/parser/test_parser.py +++ b/tests/unit/parser/test_parser.py @@ -463,7 +463,6 @@ def test__parse_basic_source(self): @mock.patch("dbt.parser.sources.get_adapter") def test__parse_basic_source_meta(self, mock_get_adapter): block = self.file_block_for(MULTIPLE_TABLE_SOURCE_META, "test_one.yml") - self.parser.manifest.files[block.file.file_id] = block.file dct = yaml_from_file(block.file) self.parser.parse_file(block, dct) self.assert_has_manifest_lengths(self.parser.manifest, sources=2)