Skip to content
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

Enforce Datetime Type for Expires on Set-Cookie #1484

Merged
merged 4 commits into from
Feb 6, 2019

Conversation

LTMenezes
Copy link
Contributor

Closes: #1453

@codecov
Copy link

codecov bot commented Feb 3, 2019

Codecov Report

Merging #1484 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1484      +/-   ##
==========================================
+ Coverage   91.44%   91.45%   +<.01%     
==========================================
  Files          17       17              
  Lines        1730     1731       +1     
  Branches      328      330       +2     
==========================================
+ Hits         1582     1583       +1     
  Misses        123      123              
  Partials       25       25
Impacted Files Coverage Δ
sanic/cookies.py 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bc7d0f0...5019007. Read the comment docs.

@LTMenezes
Copy link
Contributor Author

The CI appears to be failing for a reason outside this PR scope. It's a lint error on sanic/response.py.

Let me know if this is related to my PR or if you guys want me to fix it, I would be glad to help!

@vltr
Copy link
Member

vltr commented Feb 5, 2019

Thanks for your effort, @LTMenezes ! I guess this is something that was already been discussed, I just don't remember if there was any conclusions ... @harshanarayana , any thoughts?

@harshanarayana
Copy link
Contributor

@vltr This is something we discussed in the forum. The conclusion was to let datetime be used as a valid value and raise an exception otherwise to inform that the type is invalid. (Enables easy date to string conversion in RFC Standard)

@harshanarayana
Copy link
Contributor

@LTMenezes I looked at the travis jobs.

would reformat /home/travis/build/huge-success/sanic/sanic/cookies.py

Looks like black detected a possible format change in the code for cookies.py. Can you just run the make beautify command once and commit the changes? That should fix the travis issues.

sanic/cookies.py Outdated
@@ -1,5 +1,6 @@
import re
import string
import datetime
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just import what we need for the check here? from datetime import datetime

sanic/cookies.py Outdated
@@ -108,6 +109,11 @@ def __setitem__(self, key, value):
if key.lower() == "max-age":
if not str(value).isdigit():
value = DEFAULT_MAX_AGE
elif key.lower() == "expires":
if type(value) is not datetime.datetime:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type(x) can probably be replaced with isinstance(x, datetime) instead.

sanic/cookies.py Outdated
@@ -108,6 +109,11 @@ def __setitem__(self, key, value):
if key.lower() == "max-age":
if not str(value).isdigit():
value = DEFAULT_MAX_AGE
elif key.lower() == "expires":
if type(value) is not datetime.datetime:
raise KeyError(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more of a TypeError rather than a KeyError

@LTMenezes
Copy link
Contributor Author

Thanks for the review @harshanarayana! I applied the suggestions you made and fixed the build.

I also committed other files that the 'make beautify' command formatted, hope that this is okay.

Copy link
Contributor

@harshanarayana harshanarayana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@LTMenezes Looks like you reformatted the tests too. No worries I guess. Hope @huge-success/sanic-core-devs is okay with this.

@sjsadowski
Copy link
Contributor

Looks ok to me too.

@sjsadowski sjsadowski merged commit 08794ae into sanic-org:master Feb 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants