You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, after I updated dbt 0.20.0 to 0.21.0, the following code started giving an error. (modules.datetime.date.today()-modules.datetime.timedelta(days=modules.datetime.date.today().weekday())).strftime(“%Y-%m-%d”)
Error: ‘str object’ has no attribute ‘strftime’
I think that the part before .strftime should be datetime.date in Python, so I suspect that dbt is misinterpreting the type.
Steps To Reproduce
Create a dbt macro using the code above, like {% set monday = (modules.datetime.date.today()-modules.datetime.timedelta(days=modules.datetime.date.today().weekday())).strftime("%Y-%m-%d") %}
Hi @jtcohen6 thank you for your quick check and response!
(I'm on Python 3.8.10.)
I was looking at the wrong culprit of the error, and my current conclusion is that this is not a bug.
To emulate my dbt and database setup, if you create a file like "datatype_test.sql" with the following code under models, and run dbt compile --models datatype_test, you'll get the error I got. I can avoid the error by replacing {{v.strftime("%Y-%m-%d")}} with {{v}}.
{% set today = modules.datetime.date.today() %}
{% set monday = modules.datetime.date.today()-modules.datetime.timedelta(days=modules.datetime.date.today().weekday()) %}
{% set date_list = [] %}
{% set _ = date_list.append(today.strftime("%Y-%m-%d")) %}
{% set _ = date_list.append(monday.strftime("%Y-%m-%d")) %}
{%- for v in date_list -%}
'{{v.strftime("%Y-%m-%d")}}'
{%- endfor -%}
I cannot test this with dbt@0.20.0 at the moment, but if it runs through with it, it could be a bug, and the bug might be #3499.
@2rara That looks right to me. You're adding strings to date_list (the output of .strftime("%Y-%m-%d")), so you cannot apply .strtime() again. Just {{v}} inside the final loop does the trick.
Describe the bug
Hi, after I updated dbt 0.20.0 to 0.21.0, the following code started giving an error.
(modules.datetime.date.today()-modules.datetime.timedelta(days=modules.datetime.date.today().weekday())).strftime(“%Y-%m-%d”)
Error:
‘str object’ has no attribute ‘strftime’
I think that the part before .strftime should be datetime.date in Python, so I suspect that dbt is misinterpreting the type.
Steps To Reproduce
Create a dbt macro using the code above, like
{% set monday = (modules.datetime.date.today()-modules.datetime.timedelta(days=modules.datetime.date.today().weekday())).strftime("%Y-%m-%d") %}
Run
dbt compile
.Expected behavior
No error.
Screenshots and log output
'str object' has no attribute 'strftime'
System information
Which database are you using dbt with?
The output of
dbt --version
:The operating system you're using:
ProductName: macOS
ProductVersion: 11.6
BuildVersion: 20G165
The output of
python --version
:Python 2.7.16
Additional context
I didn't get the error when I used dbt 0.20.0.
The text was updated successfully, but these errors were encountered: