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

feat(misc): return timezone aware datetime objects #2246

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

chgad
Copy link

@chgad chgad commented Jul 13, 2024

let http_date_to_dt validate timezone information from the provided http-date and return timezone aware datetime objects remove tests for timezone naive variants
amend tests

Breaks any application relying on naiveness of datetimes or interpretation in local time. Closes #2182

Summary of Changes

Make the function http_date_to_dt validate timezone inforamtion of a http-date and return timezone aware datetime objects.

Related Issues

#2182

Pull Request Checklist

This is just a reminder about the most common mistakes. Please make sure that you tick all appropriate boxes. But please read our contribution guide at least once; it will save you a few review cycles!

If an item doesn't apply to your pull request, check it anyway to make it apparent that there's nothing to do.

  • Applied changes to both WSGI and ASGI code paths and interfaces (where applicable).
  • Added tests for changed code.
  • Prefixed code comments with GitHub nick and an appropriate prefix.
  • Coding style is consistent with the rest of the framework.
  • Updated documentation for changed code.
    • Added docstrings for any new classes, functions, or modules.
    • Updated docstrings for any modifications to existing code.
    • Updated both WSGI and ASGI docs (where applicable).
    • Added references to new classes, functions, or modules to the relevant RST file under docs/.
    • Updated all relevant supporting documentation files under docs/.
    • A copyright notice is included at the top of any new modules (using your own name or the name of your organization).
    • Changed/added classes/methods/functions have appropriate versionadded, versionchanged, or deprecated directives.
  • Changes (and possible deprecations) have towncrier news fragments under docs/_newsfragments/, with the file name format {issue_number}.{fragment_type}.rst. (Run towncrier --draft to ensure it renders correctly.)

If you have any questions to any of the points above, just submit and ask! This checklist is here to help you, not to deter you from contributing!

PR template inspired by the attrs project.

let http_date_to_dt validate timezone information from the
provided http-date and return timezone aware datetime objects
remove tests for timezone naive variants
amend tests

Breaks any application relying on naiveness of datetimes or
interpretation in local time. Closes falconry#2182
@vytas7 vytas7 changed the title feat(misc): Return timezone aware datetime objects feat(misc): return timezone aware datetime objects Jul 13, 2024
Copy link

codecov bot commented Jul 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.97%. Comparing base (09189a8) to head (107e2f0).

Additional details and impacted files
@@             Coverage Diff             @@
##            master    #2246      +/-   ##
===========================================
- Coverage   100.00%   99.97%   -0.03%     
===========================================
  Files           63       63              
  Lines         6847     6853       +6     
  Branches      1258     1259       +1     
===========================================
+ Hits          6847     6851       +4     
- Misses           0        1       +1     
- Partials         0        1       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@CaselIT CaselIT left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

I've left a couple of comments

@@ -29,7 +29,7 @@ def dst(self, dt):


def utcnow_naive():
Copy link
Member

Choose a reason for hiding this comment

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

could likely rename this function to utcnow or use the one from misc from falcon.util.misc import _utcnow like in test_middleware.py

Copy link
Author

Choose a reason for hiding this comment

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

Sounds reasonable, will change.

@@ -252,26 +252,15 @@ def test_unset(cookie, samesite='Lax'):
assert not result_unset.cookies['baz'].same_site


def test_cookie_expires_naive(client):
Copy link
Member

Choose a reason for hiding this comment

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

If I'm not mistaken it's still allowed to set expire to a naive datetime, so this test should be kept. maybe it needs to be updated to check that expire has a timezone?

Copy link
Author

Choose a reason for hiding this comment

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

According to the RFC 9910 every HTTP-date has to follow the implemented rules. That'S the reason for the deletion for the test. The test fails since, whti the new change, naive dates are no longer allowed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

http_date_to_dt() should return a timezone-aware datetime
3 participants