{"record":{"id":"608416e6c37e8661","repo":"dbt-labs/dbt-core","slug":"diff-of-two-dicts-requires-a-dict-a-argument","errorCode":null,"errorMessage":"diff_of_two_dicts requires a dict_a argument","messagePattern":"diff_of_two_dicts requires a dict_a argument","errorType":"validation","errorClass":"InvalidOperation","httpStatus":null,"severity":"error","filePath":"crates/dbt-jinja-utils/src/functions/base.rs","lineNumber":614,"sourceCode":"    }\n}\n\n/// A function that returns the difference between two dictionaries\n/// Not documented in dbt Jinja docs, but included in base.py\npub fn diff_of_two_dicts_fn() -> impl Fn(&[Value], Kwargs) -> Result<Value, Error> {\n    move |args: &[Value], kwargs: Kwargs| -> Result<Value, Error> {\n        if args.len() != 2 {\n            return Err(Error::new(\n                ErrorKind::InvalidOperation,\n                \"diff_of_two_dicts requires exactly 2 arguments\",\n            ));\n        }\n\n        let dict_a_arg = match (kwargs.get(\"dict_a\"), args.first()) {\n            (Ok(value), _) => value,\n            (_, Some(value)) => value,\n            _ => {\n                return Err(Error::new(\n                    ErrorKind::InvalidOperation,\n                    \"diff_of_two_dicts requires a dict_a argument\",\n                ));\n            }\n        }\n        .clone();\n\n        let dict_b_arg = match (kwargs.get(\"dict_b\"), args.get(1)) {\n            (Ok(value), _) => value,\n            (_, Some(value)) => value,\n            _ => {\n                return Err(Error::new(\n                    ErrorKind::InvalidOperation,\n                    \"diff_of_two_dicts requires a dict_b argument\",\n                ));\n            }\n        }\n        .clone();","sourceCodeStart":596,"sourceCodeEnd":632,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-jinja-utils/src/functions/base.rs#L596-L632","documentation":"diff_of_two_dicts validates that a value for dict_a is available, either via the dict_a kwarg or the first positional argument. When neither is present the function throws this InvalidOperation error. It is a required-argument check distinct from the arity check.","triggerScenarios":"Calling diff_of_two_dicts() with zero positional args and no dict_a kwarg, or calling it with only dict_b=... supplied. Notably this fires with 2+ args only if lookup order breaks, but practically it fires on the missing-dict_a call shape.","commonSituations":"Kwargs/positional mixing mistakes: developers pass dict_b= keyword only and forget dict_a; templates built programmatically where the first positional slot ends up empty.","solutions":["Provide the first dict positionally: diff_of_two_dicts(a, b)","Or pass it explicitly: diff_of_two_dicts(dict_a=a, dict_b=b)","Check that the variable holding dict_a is defined and not undefined at render time"],"exampleFix":"// before\n{% set diff = diff_of_two_dicts(dict_b=other) %}\n// after\n{% set diff = diff_of_two_dicts(dict_a=my_dict, dict_b=other) %}","handlingStrategy":"validation","validationCode":"{% if dict_a is not defined %}\n  {{ exceptions.raise_compiler_error('dict_a is required before diff_of_two_dicts in ' ~ this) }}\n{% endif %}","typeGuard":"{% macro is_dict(x) %}{{ return(x is defined and x is mapping) }}{% endmacro %}","tryCatchPattern":null,"preventionTips":["When mixing kwargs and positionals, always provide dict_a explicitly","Check variable definitions with `is defined` before helper calls","Keep argument order consistent across a project"],"tags":["jinja","dbt","missing-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"0267ce9170576975b76b64ce856b2e5848e96617","analyzedAt":"2026-09-07T21:53:39.732Z","contentChangedAt":"2026-09-07T21:53:39.732Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}