Surrogate key dbt upgrade

I just did a dbt upgrade from v.1.0 → v1.3 and also upgraded all dependencies, packages along with it as things were breaking. I’m facing a recurring problem in “dbt seed” and macros in each run - where a surrogate key function is failing repeatedly

Need to fix this so upgrade goes smoothly


dbt seed
10:26:16  Running with dbt=1.3.2
10:26:16  Partial parse save file not found. Starting full parse.
Compilation Error in model website_sessionized (models/marts/marketing/attribution/website_sessionized.sql)
  Warning: `dbt_utils.surrogate_key` has been replaced by `dbt_utils.generate_surrogate_key`. The new macro treats null values differently to empty strings. To restore the behaviour of the original macro, add a global variable in dbt_project.yml called `surrogate_key_treat_nulls_as_empty_strings` to your dbt_project.yml file with a value of True. The vauld_analytics.website_sessionized model triggered this warning. 

What I’ve already tried

Previous code :-

{{ dbt_utils.surrogate_key(['anonymous_id', 'session_number']) }} AS session_id 

New code :-

{{ dbt_utils.generate_surrogate_key(['anonymous_id', 'session_number']) }} AS session_id # 

Also, tried adding the global variable in project.yml

#1.3 v fix
    #surrogate_key_treat_nulls_as_empty_strings: true - not working

Not sure what’s the solution here to add the new command for surrogate key - any help is appreciated

I recommend you double-check if you have no leftover usages of the legacy dbt_utils.surrogate_key, as according to the warning, you have one in website_sessionized.
Maybe this model is using a macro that uses the legacy function, I’d check it out too.

As for your latest question, you probably would like to add it for backward compatibility. Since the legacy function was treating null as if they were empty strings, in order to yield the same results as before, you would like to use this flag.

1 Like

Thanks tomer, I think I found the main issue and fixed it - it was just replacing legacy with new generate_surrogate_key and with the macro definition in yml file clearly at top

However, getting a new error on another object that’s causing an issue

'dict object' has no attribute 'datediff'. This can happen when calling a macro that does not exist. Check for typos and/or install package dependencies with "dbt deps".