Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Bilbottom opened this issue Dec 21, 2024 · 3 comments · Fixed by #3559
Closed

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

Bilbottom opened this issue Dec 21, 2024 · 3 comments · Fixed by #3559
Assignees
Labels
Bug Something isn't working

Comments

@Bilbottom
Copy link

Bilbottom commented Dec 21, 2024

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
@treysp treysp self-assigned this Dec 22, 2024
@treysp treysp added the Bug Something isn't working label Dec 22, 2024
@treysp
Copy link
Contributor

treysp commented Dec 22, 2024

Hello - thank you for reporting this and for a thorough description!

Your example runs without error for me, so based on the Python docs I suspect the issue is differences in strftime support across OSs.

I think the minus sign - in %-I may be the culprit here. Could you check whether this modified formatting string runs without error?

import datetime

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

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

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

@Bilbottom
Copy link
Author

@treysp thanks for the quick response -- I tried your modified version, and that works fine for me 😄

image

@fdcastel
Copy link

@treysp I've encountered this issue as well.

While a new version with the fix is not yet available, is there a workaround involving adjustments to the SQLMesh configuration?

The documentation explains how to set the date format for INCREMENTAL_BY_TIME_RANGE. However, I'm using SCD_TYPE_2_BY_COLUMN, which uses updated_at_name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants