fix: rely on naive datetime for sqlalchemy#1833
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1833 +/- ##
==========================================
+ Coverage 83.96% 83.98% +0.01%
==========================================
Files 116 117 +1
Lines 13221 13243 +22
==========================================
+ Hits 11101 11122 +21
- Misses 2120 2121 +1 ☔ View full report in Codecov by Sentry. |
| token: ${{ secrets.CODECOV_TOKEN }} | ||
| verbose: true | ||
|
|
||
| databases: |
There was a problem hiding this comment.
This new job spins up a postgrrrresql db that can then be used to run our unit tests against, it should prevent this type of issue from coming up again 🚀
I tried adding mysql as well but it was failing, I'll it to my TODOs as a follow up PR
vegeris
left a comment
There was a problem hiding this comment.
So we've been converting datetimes into UTC but they were interpreted as local times by some databases because the datetime object didn't include the timezone info, so now we have to maintain that behaviour until the next major version, IIUC?
Changes LGTM!
@vegeris yess exactly! |
zimeg
left a comment
There was a problem hiding this comment.
@WilliamBergamin LGTM and thanks for diving into these edges so much 🤖
Let's continue to support UTC for time internals! ⌛ ✨
| if dt.tzinfo is not None: | ||
| return dt.replace(tzinfo=None) |
There was a problem hiding this comment.
🪬 question(non-blocking): Should we check that tzinfo is UTC before removing it? Or converting this first? I haven't explored SQLAlchemy enough but timezones confuse me sincere...
There was a problem hiding this comment.
So when the tzinfo is not provided SQLAlchemy sets the type as "datetime timezone unaware" and uses utc as the default
If we set tzinfo=utc then SQLAlchemy sets the type as "datetime timezone aware" which creates a breaking change with POSTGRESQL
Summary
Changes from #1798 resulted in #1832
Some databases like PostgresSQL support timezone aware
datetimeobjects, the currentsqlalchemyinterface does not support datetime aware object resulting in the following errorIn order to maintain backward compatibility these changes allow the SDK to support naive datetime objects
Testing
The new integration tests should validate that the changes work with postgreSQL
Category
/docs(Documents)/tutorial(PythOnBoardingBot tutorial)tests/integration_tests(Automated tests for this library)Requirements
python3 -m venv .venv && source .venv/bin/activate && ./scripts/run_validation.shafter making the changes.