dbt-labs / dbt-labs/dbt-adapters
OverflowError when querying DATE column with values beyond year 9999 using dbt-snowflake
- Dominant language
- Python
- Stars
- 233
- Forks
- 362
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 9
Description
### Is this a new bug?
- [x] I believe this is a new bug
- [x] I have searched the existing issues, and I could not find an existing issue for this bug
### Which packages are affected?
- [ ] dbt-adapters
- [ ] dbt-tests-adapter
- [ ] dbt-athena
- [ ] dbt-athena-community
- [ ] dbt-bigquery
- [ ] dbt-postgres
- [ ] dbt-redshift
- [x] dbt-snowflake
- [ ] dbt-spark
### Current Behavior
When using `dbt-snowflake` to query a Snowflake table that contains `DATE` values with years greater than four digits (e.g., 10007), the following error is raised:
> `ERROR:snowflake.connector.result_batch:Failed to convert: field MAXVALUE: DATE::2935611, Error: date value out of range
> Traceback (most recent call last):
> File "C:\CODE_BASE\services\dbtdataprofiler\dbt_env\lib\site-packages\snowflake\connector\converter.py", line 210, in conv
> return datetime.utcfromtimestamp(int(value) * 86400).date()
> OSError: [Errno 22] Invalid argument
>
> During handling of the above exception, another exception occurred:
>
> Traceback (most recent call last):
> File "C:\CODE_BASE\services\dbtdataprofiler\dbt_env\lib\site-packages\snowflake\connector\result_batch.py", line 483, in _parse
> row_result[idx] = v if c is None or v is None else c(v)
> File "C:\CODE_BASE\services\dbtdataprofiler\dbt_env\lib\site-packages\snowflake\connector\converter.py", line 213, in conv
> ts = ZERO_EPOCH + timedelta(seconds=int(value) * (24 * 60 * 60))
> OverflowError: date value out of range
> 15:38:26 Encountered an error while running operation: Runtime Error
> 252005: Failed to convert: field MAXVALUE: DATE::2935611, Error: date value out of range`
However, the same SQL query runs successfully when executed directly in the Snowflake UI or CLI.
### Expected Behavior
dbt should correctly handle large DATE values (years > 9999) if Snowflake supports them.
### Steps To Reproduce
1. Create a table in snowflake DB:
> `create table dummy (id integer, fecha date);`
2. Insert data in the table:
> insert into dummy values (1, '1980-01-01');
insert into dummy values (2, '3003-04-02');
insert into dummy values (3, '9001-06-03');
insert into dummy values (4, '10007-06-07');
3. Run this query through dbt-snowflake:
> select max("FECHA") as maxValue from "SCHEMADRIFT"."DUMMY";
### Relevant log output
```shell
`ERROR:snowflake.connector.result_batch:Failed to convert: field MAXVALUE: DATE::2935611, Error: date value out of range
Traceback (most recent call last):
File "C:\CODE_BASE\services\dbtdataprofiler\dbt_env\lib\site-packages\snowflake\connector\converter.py", line 210, in conv
return datetime.utcfromtimestamp(int(value) * 86400).date()
OSError: [Errno 22] Invalid argument
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\CODE_BASE\services\dbtdataprofiler\dbt_env\lib\site-packages\snowflake\connector\result_batch.py", line 483, in _parse
row_result[idx] = v if c is None or v is None else c(v)
File "C:\CODE_BASE\services\dbtdataprofiler\dbt_env\lib\site-packages\snowflake\connector\converter.py", line 213, in conv
ts = ZERO_EPOCH + timedelta(seconds=int(value) * (24 * 60 * 60))
OverflowError: date value out of range
15:38:26 Encountered an error while running operation: Runtime Error
252005: Failed to convert: field MAXVALUE: DATE::2935611, Error: date value out of range`
```
### Environment
```markdown
- OS: Linux (Dockerized image is used) / Windows 11
- Python: 3.10.17
- dbt-snowflake:1.7.5
- dbt-core: 1.7.0
```
### Additional Context
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.