-
Notifications
You must be signed in to change notification settings - Fork 846
fix: move away from datetime.utcfromtimestamp for the state and installation stores #1798
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
base: main
Are you sure you want to change the base?
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1798 +/- ##
=======================================
Coverage 83.90% 83.91%
=======================================
Files 115 115
Lines 13080 13080
=======================================
+ Hits 10975 10976 +1
+ Misses 2105 2104 -1 ☔ View full report in Codecov by Sentry. |
zimeg
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super nice changes! I left a comment around the effects of these changes and I'm also curious if #1731 might be addressed with this too?
I'm marking this as "approved" but do let me know if more review and testing can be helpful 🙏 ✨
| "installed_at": datetime.utcfromtimestamp(self.installed_at), | ||
| "installed_at": datetime.fromtimestamp(self.installed_at, tz=timezone.utc), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤩 praise: @WilliamBergamin I'm a huge fan of keeping all representations of time in the UTC timezone!
👁️🗨️ question: Would adjacent implementations also require a similar change? I find this initial value might be generated with an offset:
python-slack-sdk/slack_sdk/oauth/installation_store/models/installation.py
Lines 131 to 134 in d7caaf4
| if installed_at is None: | |
| self.installed_at = datetime.now().timestamp() | |
| else: | |
| self.installed_at = _timestamp_to_type(installed_at, float) |
📚 https://docs.python.org/3/library/datetime.html#datetime.datetime.now
Summary
This PR aims to resolve #1676 by favoring the following
datetime.utcfromtimestamp(...)->datetime.fromtimestamp(..., tz=timezone.utc)datetime.utcnow()->datetime.now(tz=timezone.utc)Some investigation was required to ensure this change would not impact existing application. Since the timestamps are stored and compared as integers this change should not cause any breaking change.
Testing
Unit test coverage should be sufficient
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.