Skip to content

Bug: Failed to convert expected value into datetime for out-of-bounds nanosecond timestamp 0001-01-01 00:00:00 in unit tests #5929

Description

@ShivaniKale0

Bug Description:
When writing a SQLMesh unit test that includes a TIMESTAMP column with the value 0001-01-01 00:00:00, the test runner throws the following warnings and fails to compare the expected and actual values correctly.

[WARNING] Failed to convert expected value for timestamp_field
into datetime for unit test 'test_model'
(tests\test_model.yaml)'.
Out of bounds nanosecond timestamp: 0001-01-01 00:00:00, at position 0.

The value 0001-01-01 00:00:00 is a valid SQL TIMESTAMP but falls outside the range that pandas can handle with nanosecond precision (which starts at 1677-09-21).

Steps to Reproduce:

  1. Create a model with a TIMESTAMP column that can contain '0001-01-01 00:00:00'.
  2. Write a unit test with that value in the expected output
  3. Run SQLMesh test

Expected Behaviour:
The test should either:
Successfully compare the timestamp values, or
Provide a clear error message with a suggested workaround

Actual Behaviour:
The test throws a 'Failed to convert expected value into datetime' warning, and the comparison fails.

Attempted Workarounds:
The following workarounds were attempted but did not resolve the issue:

  • Specifying the column type as VARCHAR in the columns attribute of the test
  • Using a SQL query format for the expected output with explicit CAST
  • Using explicit CAST('0001-01-01 00:00:00' AS VARCHAR) in the output query
  • Adding column_definitions to the model.

Environment:
SQLMesh version: 0.227.1
Database dialect: Redshift

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions