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

Datetime issue with Python 3.11 (with fix) #2694

Closed
1 task done
stricaud opened this issue Feb 24, 2023 · 3 comments
Closed
1 task done

Datetime issue with Python 3.11 (with fix) #2694

stricaud opened this issue Feb 24, 2023 · 3 comments
Labels

Comments

@stricaud
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I am getting various exceptions like this:

[2023-02-24 22:41:25 +0100] [512643] [ERROR] Exception in static request handler: path=static, relative_url=fonts/general.woff2
Traceback (most recent call last):
  File "/home/sebastien/.local/lib/python3.11/site-packages/sanic/mixins/routes.py", line 848, in _static_request_handler
    response = await validate_file(request.headers, modified_since)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sebastien/.local/lib/python3.11/site-packages/sanic/response/convenience.py", line 151, in validate_file
    if last_modified <= if_modified_since:
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: can't compare offset-naive and offset-aware datetimes

Which is fixed by ensuring last_modified and if_modified_since are converted to proper timestamps():

if last_modified.timestamp() <= if_modified_since.timestamp():

Code snippet

No response

Expected Behavior

No response

How do you run Sanic?

Sanic CLI

Operating System

Linux Debian

Sanic Version

Sanic 22.12.0; Routing 22.8.0

Additional context

No response

@stricaud stricaud added the bug label Feb 24, 2023
@ahopkins
Copy link
Member

Excellent. Can you open a PR with this fix and a unit test?

@stricaud
Copy link
Contributor Author

absolutely

@stricaud
Copy link
Contributor Author

Done with PR #2697 2697

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

No branches or pull requests

2 participants