tsql-utils icon indicating copy to clipboard operation
tsql-utils copied to clipboard

`date_spine` isn't working with `dbt_utils 1.1.0`

Open romiof opened this issue 1 year ago • 5 comments

Hello!

I'm trying to run a date_spine to populate my Calendar Dimension, but it crash with Compilation Error:

23:29:43  Running with dbt=1.4.6
23:29:44  Encountered an error:
Compilation Error in model DimCalendar (models/03_dimensions/DimCalendar.sql)
  'dict object' has no attribute 'datediff'
  
  > in macro sqlserver__date_spine (macros/dbt_utils/datetime/date_spine.sql)
  > called by macro date_spine (macros/sql/date_spine.sql)
  > called by model DimCalendar (models/03_dimensions/DimCalendar.sql)

Version info:

dbt --version
Core:
  - installed: 1.4.6
  - latest:    1.5.1 - Update available!

  Your version of dbt-core is out of date!
  You can find instructions for upgrading here:
  https://docs.getdbt.com/docs/installation

Plugins:
  - sqlserver: 1.4.3 - Up to date!
packages:
  - package: dbt-labs/dbt_utils
    version: ["1.1.0"]
  - package: calogica/dbt_date
    version: ["0.7.2"]
  - package: dbt-msft/tsql_utils
    version: ["0.9.0"]

With a regression to dbt_utils 0.9.0 date_spine worked, but had some warns:

> Executing task: dbt compile --model DimCalendar
23:35:07  Running with dbt=1.4.6
23:35:07  [WARNING]: Configuration paths exist in your dbt_project.yml file which do not apply to any resources.
There are 1 unused configuration paths:
- tests
23:35:07  Found 65 models, 0 tests, 0 snapshots, 1 analysis, 695 macros, 0 operations, 10 seed files, 199 sources, 0 exposures, 0 metrics
23:35:07  
23:35:08  Concurrency: 4 threads (target='dev')
23:35:08  
23:35:08  Warning: the `datediff` macro is now provided in dbt Core. It is no longer available in dbt_utils and backwards compatibility will be removed in a future version of the package. Use `datediff` (no prefix) instead. The dbt_sazi.DimCalendar model triggered this warning.
23:35:08  Warning: the `dateadd` macro is now provided in dbt Core. It is no longer available in dbt_utils and backwards compatibility will be removed in a future version of the package. Use `dateadd` (no prefix) instead. The dbt_sazi.DimCalendar model triggered this warning.
23:35:08  Done.

romiof avatar Jun 02 '23 23:06 romiof

My model content:

{{ dbt_utils.date_spine(
    datepart="day",
    start_date="cast('2020-01-01' as date)",
    end_date="cast('2020-01-31' as date)"
   )
}}

romiof avatar Jun 02 '23 23:06 romiof

I am also have this exact same problem. I believe that Pull Request #90 will fix this issue. Problem is that dbt-core was updated to include dateadd and datediff among other cross-database macros and dbt-utils was subsequently modified, but in the current (0.9.0) version of tsql-utils the date_spine is still referencing dbt_util.dateadd and dbt_util.datediff intead of dbt.dateadd and dbt.datediff. The pull request fixes that.

brent3-work avatar Jun 12 '23 14:06 brent3-work

I am having the exact same Problem, adjusting the tsql_utils date _spine macro from dbt_utils.datediff to dbt.datediff fixes the issue, as @brent3-work proposed.

ghost avatar Aug 09 '23 11:08 ghost

#100

I proposed a bugfix on this PR.

joaquinbravo23 avatar Dec 22 '23 14:12 joaquinbravo23

I had the same problem here running on Linux on a remote build VM with,

  • dbt-core==1.7.14
  • dbt-sqlserver==1.7.4
  • dbt-labs/dbt_utils==1.1.1
  • dbt-labs/audit_helper==0.11.0
  • dbt-msft/tsql_utils==0.10.0

Didn't have the problem on my development desktop running on MacOS though.

and @joaquinbravo23 patch solved my problem, thanks to him for spotting the problem.

mycaule avatar May 07 '24 17:05 mycaule

should be fixed, report back if not please

sdebruyn avatar Sep 08 '24 11:09 sdebruyn