Skip to content

Format string %Y-%m-%d %-I:%M%p %Z is invalid (Python 3.11.5) #3555

@billwallis

Description

@billwallis

Summary

When I run sqlmesh run with SQLMesh 0.141.1 and Python 3.11.5, it returns the following error:

...

 File "...\Lib\site-packages\sqlmesh\utils\date.py", line 431, in format_tz_datetime
    output_datetime.strftime(format_string)
ValueError: Invalid format string

I tweaked the format_tz_datetime function in my environment to print the values it was trying to use, which are:

output_datetime:  datetime.datetime(2024, 12, 22, 0, 0, tzinfo=datetime.timezone.utc)
format_string:    '%Y-%m-%d %-I:%M%p %Z'

The error seems to be coming from the datetime library because of the %Y-%m-%d %-I:%M%p %Z timestamp defined at:

MWE

Since the underlying error seems to be coming from the datetime library, here's a pure Python MWE to replicate the error with this timestamp:

import datetime

output_datetime = datetime.datetime(2024, 12, 22, 0, 0, tzinfo=datetime.timezone.utc)
format_string = "%Y-%m-%d %-I:%M%p %Z"

print("output_datetime:", repr(output_datetime))
print("format_string:", repr(format_string))

# fails here
print(output_datetime.strftime(format_string))

Environment details

  • OS: Windows 10
  • Python version: 3.11.5
  • SQLMesh version: 0.141.1

Comparison to 0.139.0

To confirm that this is indeed a new issue, I took the following steps:

  • Rebuilt my pipeline from scratch locally using SQLMesh 0.139.0
  • Applied the plan successfully (sqlmesh plan)
  • Ran sqlmesh run without error (just to confirm that the command works)
  • Upgraded to SQLMesh 0.141.1 (pip install sqlmesh==0.141.1)
  • Upgraded to the latest SQLMesh migration (sqlmesh migrate)
  • Ran sqlmesh run again, but hit the error

Metadata

Metadata

Assignees

Labels

BugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions