-
Notifications
You must be signed in to change notification settings - Fork 91
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
Datetime Autoconversion for Timestamptz Columns #959
base: master
Are you sure you want to change the base?
Conversation
Thanks for this. I think it makes sense.
|
@dantownsend The initial proposal contained some shortcomings which should be fully fixed by the subsequent commits. |
It's looking good, thanks. It seems like there's some minor linter and test issues. |
@aabmets Sorry to intrude into this conversation, but first you need to run linters and tests locally with this set of commands, (then you'll see what you need to fix)
Code contribution guide is here and code style is here. Hope this help to pass linters check and tests |
@sinisaos Thanks for the help, I'll try doing that option. |
@sinisaos Okay, i think i got it fixed now. Can we try again the workflow? |
…ordering with isort
…s, migration tests are not fixed
@sinisaos |
@dantownsend Okay I think I've done it, the linting and unittests should be fixed now. |
@aabmets Sorry for the late reply. When I start formatting, a lot of files are not well formatted and to satisfy mypy in Python3.8 I have to |
@sinisaos hey, thanks for also taking a look at possible solutions. I think my latest commits fixed both linting and test issues, now waiting for approval to rerun workflow. |
For crying out loud 😂 why is the god damn linter test suite failing. I ran the linting and style commands on the commited files. |
@sinisaos Would you be so kind as to re-run the CI workflow, thanks. |
@aabmets I'm sorry, but I'm not a maintainer and I don't have permission to do that. You have to wait for @dantownsend for that. Daniel, can you please fix this issue with linters as |
@sinisaos yes, will try and do it later tonight. I've given you extra permissions now, so in the future you should be able to approve running CI. GitHub permissions are a bit confusing. |
@dantownsend @sinisaos Hey, at least we're seeing some improvements! I see only one failing test now. |
@aabmets To satisfy mypy in Python3.8 try to
@dantownsend Thanks. I also don't know much about Github permissions. |
@sinisaos Done. I couldn't find a solution how to surgically disable MyPy from |
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #959 +/- ##
==========================================
+ Coverage 92.02% 92.82% +0.80%
==========================================
Files 108 108
Lines 8246 8207 -39
==========================================
+ Hits 7588 7618 +30
+ Misses 658 589 -69 ☔ View full report in Codecov by Sentry. |
@dantownsend @sinisaos try:
from zoneinfo import ZoneInfo # type: ignore
except ImportError: # pragma: no cover <-- necessary to add to silence codecov
from backports.zoneinfo import ZoneInfo # type: ignore # noqa: F401 |
@aabmets Yes, if you don't mind - we use |
piccolo/table.py
Outdated
try: | ||
from zoneinfo import ZoneInfo # type: ignore | ||
except ImportError: # pragma: no cover | ||
from backports.zoneinfo import ZoneInfo # type: ignore # noqa: F401 | ||
|
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.
@aabmets I think you should remove this imports as it is not used anywhere in the file
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.
@sinisaos Done
@dantownsend Not to be a bother, but would it be perchance possible to merge this PR into master and release a minor version in the near future? |
@dantownsend Sure, I'll try tomorrow. |
@dantownsend I tested this PR a bit. # objects query
In [1]: [i.to_dict() for i in await TallinnConcerts.objects()]
Out[1]:
[{'id': 1,
'event_start': datetime.datetime(2050, 1, 1, 21, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Tallinn'))},
{'id': 2,
'event_start': datetime.datetime(2050, 1, 1, 21, 0, tzinfo=zoneinfo.ZoneInfo(key='Europe/Tallinn'))}]
# select queries
In [2]: await TallinnConcerts.select()
Out[2]:
[{'id': 1,
'event_start': datetime.datetime(2050, 1, 1, 19, 0, tzinfo=datetime.timezone.utc)},
{'id': 2,
'event_start': datetime.datetime(2050, 1, 1, 19, 0, tzinfo=datetime.timezone.utc)}] I don't know if this is expected behavior (or I'm doing something wrong), but it doesn't match this lines from the docstring. piccolo/piccolo/columns/column_types.py Lines 983 to 991 in db53939
|
@sinisaos Thanks for testing it - that's very helpful. |
@dantownsend I found another problem. When we try to bulk update a column in Piccolo Admin, the fields don't show up in dropdown with the changes from this PR. bulk_update.webm |
I've had a chance to test this now. As @sinisaos says, the issue at the moment is with I think instead we might be able to modify the select query SQL to use |
Using Edit: I managed to work around this. Now I have Edit 2: I have |
Besides writing some docs, and a few more tests, I think this is done now: It just adds a few things to this original PR. You can override the timezone in a select query: await Concert.select(Concert.starts.at_time_zone('America/New_York')) |
@dantownsend @sinisaos Thank you for taking the time to test and improve this PR. I do have a question about the proposed solution to the select queries. If a column is designated as Timestamptz with tz information set with ZoneInfo, that column identifies itself as only existing in that timezone, meaning that whenever a value of that column is being accessed, the user can be confident that the value is in the timezone that they defined the column as. When the user is able to override the timezone information with EDIT: |
I made this pull request to rectify the issue where Piccolo does not provide a way to tell Timestamptz columns in which timezones they should identify themselves as.
Outtake from PG docs:
The solutions provided by Postgres as by which it determines the timezone to convert the value back to was not working properly with Piccolo. Hence I made this pull request. It works, please merge. Kinda need it in my enterprise project. @dantownsend