dbt-msft / tsql-utils

dbt-utils for the dbt-msft family of packages
MIT License
25 stars 24 forks source link

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

Open romiof opened 1 year ago

romiof commented 1 year ago

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:

```sh 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! ``` ```yml 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 commented 1 year ago

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)"
   )
}}
brent3-work commented 1 year ago

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.

ghost commented 11 months ago

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.

joaquinbravo23 commented 6 months ago

100

I proposed a bugfix on this PR.

mycaule commented 2 months ago

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

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.