-
Notifications
You must be signed in to change notification settings - Fork 22
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
Forbid wrong 'expires' values when low-level API is used that silently results in always expired responses #287
Forbid wrong 'expires' values when low-level API is used that silently results in always expired responses #287
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #287 +/- ##
==========================================
+ Coverage 96.41% 96.51% +0.10%
==========================================
Files 10 10
Lines 1059 1063 +4
Branches 185 186 +1
==========================================
+ Hits 1021 1026 +5
+ Misses 29 28 -1
Partials 9 9 ☔ View full report in Codecov by Sentry. |
@layday Would you like to take a look on this change? |
8c674e2
to
ee27a81
Compare
ee27a81
to
26bf273
Compare
Do you have time to publish a patch release for this? If not, I can do that after work today. |
I think there is no rush to release this immediately. Please update the changelog and release a package today/tomorrow if you have time. In the meantime, maybe someone else will provide a feedback based on the "main" branch. |
Sure, sounds good. |
Hi @JWCook @alessio-locatelli, can you please release a version with this fix? |
@JWCook @alessio-locatelli I tried to use And got a failure:
So I believe the original issue still exists? |
@shaked-seal If you stored aware datetimes to the cache manually, this can be a leftover from the previous package version. Try to clean the cache. |
I was able to reproduce when overriding "expires" to have a time-zone. We removed that. I added a check that when using CachedResponse the expires shouldn't be with timezone. Thank you for the quick fix! |
This PR closes #286
As I explained on that page:
convert_to_utc_naive()
is not called for low-level API and it is a user responsibility to convert to a naive datetime. On our side we can raise an error.save_response()
andfrom_client_response()
allow to save any random object asexpires
, including classes, functions, etc. and all these bad things work silently.An alternative solution is moving
convert_to_utc_naive()
call inside thefrom_client_response()
.Notes:
AttributeError
is impossible becauseself.expires = None
is the default class attribute.TypeError
is handled now by verifying that we work with a naive datetime.ValueError
- I have no idea how you can get it when you compare twodatetime
objects. Perhaps an old leftover.Breaking changes:
There are no breaking changes.
Users who used the low-level functions directly (
save_response()
andfrom_client_response()
) incorrectly by passing a wrongexpires
value will get an error. This is expected because so far, with the old code, their cache never worked correctly.The commit history is clean and tidy, so do not squash the commits.