Several endpoints using reltime(): TypeError: can't subtract offset-naive and offset-aware datetimes #15
Labels
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: digimint/taskflower#15
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
When deploying with gunicorn and using postgres as a backing database, something goes wrong with the
reltime()helper function. The invite code is successfully generated, but flask is then unable to render the result due to the aforementioned errors involving datetime arithmetic, thus leaving the afflicted pages permanently offline.Seems like the database info is okay, but
datetime.now()is returning timezone-unaware in prod???i just checked and it seems like it's doing the same thing on my local machine, but it didn't cause problems in that case - probably because sqlite didn't store the timezone info.
A quick test indicates that using
zoneinfo.ZoneInfoto insert a timezone into the locally-stored datetimes seems to resolve the issue. Need to turn this into a patch.it's happening in the expiration verification functions as well, bc of course it is.
Files that need to be fiddled with:
__init__.pyauth/startup.pydb/model/codes.pyform/user.pysanitize/task.pyweb/invite/__init__.pyCurrent plan is to implement timezone awareness in
util/time, and switch everything over fromdatetime.now()to a timezone-aware system. Also going to try and implement client-side timestamp rendering while i'm at it.The template macro
reltime()(usable within the codebase asutil.time.render_reltime()) has been updated to return something like:Now, we can use javascript on the client side to update the timestamp in real time, but users with js disabled will still get a correct value (based on the time they requested the page).
Also, we now have
abstime()(util.time.render_abstimewithin the codebase) which renders:ALSO, we have
util.time.from_local()which we need to use to ingest time data from the user. i'm thinking we use an invisble field on all forms that take in time (at present, that's just the task creation field).ALSO, i'm working on parsing functions to make the input more user-friendly (so you can put in a due date as 'tomorrow' or 'next week')
Structure of a 'relative' user timestamp is something like:
We can probably have both the relative time and the date picker, and let users fill out one or the other.
taskflower.util.timenow has several helper functions.taskflower.util.time.now()should be preferred overdatetime.now()in most cases.taskflower.util.time.render_reltime()andrender_abstime()should be used when rendering HTML for the user - or, from jinja, the always-availablereltime()andabstime(). Make sure to mark the result as safe.