-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Revisit last_modified in StreamResponse #5313
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5313 +/- ##
==========================================
- Coverage 97.16% 97.15% -0.02%
==========================================
Files 41 41
Lines 8739 8742 +3
Branches 1402 1403 +1
==========================================
+ Hits 8491 8493 +2
Misses 129 129
- Partials 119 120 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
) | ||
elif isinstance(value, datetime.datetime): | ||
if not value.tzinfo: |
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.
There is no easy way to create tz-aware local current time.
In turn, datetime.now()
is widely used as local naive time.
datetime.utcnow()
usage is discouraged for the sake of datetime.now(tz=timezone.utc)
.
So, I suggest dropping this warning but replacing value.utctimetuple()
with value.timetuple()
a few lines below.
https://docs.aiohttp.org/en/stable/web_reference.html?highlight=last_modified#aiohttp.web.StreamResponse.last_modified should describe how the library works with naive time objects.
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.
So, I guess there are 3 cases in new behaviour:
-
Naive
datetime
is used.
Must be considered as UTC. Documentation clearly describes this case. -
tz-aware
datetime
is used and timezone isutc
.
All is ok, user gave us correct object. -
tz-aware
datetime
is used and timezone is notutc
.
That's definitely wrong input to use withvalue.timetuple()
.ValueException
should be raised.
Is that correct?
I know, the change is not backward compatible but I don't see a smooth transition. |
To make the change more gradual we would need to emit FutureWarning, and change the behavior only after passing some period (a year or two). But if most of uses of naive datetime objects are |
@@ -259,9 +259,17 @@ def last_modified( | |||
self._headers.pop(hdrs.LAST_MODIFIED, None) | |||
elif isinstance(value, (int, float)): | |||
self._headers[hdrs.LAST_MODIFIED] = time.strftime( | |||
"%a, %d %b %Y %H:%M:%S GMT", time.gmtime(math.ceil(value)) | |||
"%a, %d %b %Y %H:%M:%S GMT", time.gmtime(math.floor(value)) |
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.
The floor is unneeded, gmtime() already does that.
"%a, %d %b %Y %H:%M:%S GMT", time.gmtime(math.floor(value)) | |
"%a, %d %b %Y %H:%M:%S GMT", time.gmtime(value) |
What do these changes do?
Bug fixes related to
last_modified
attribute inStreamResponse
object.Are there changes in behavior for the user?
Nope.
Related issue number
#5303, #5304
Checklist
CONTRIBUTORS.txt
CHANGES
folder<issue_id>.<type>
for example (588.bugfix)issue_id
change it to the pr id after creating the pr.feature
: Signifying a new feature..bugfix
: Signifying a bug fix..doc
: Signifying a documentation improvement..removal
: Signifying a deprecation or removal of public API..misc
: A ticket has been closed, but it is not of interest to users.