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

OverflowError: mktime argument out of range #275

Closed
balihb opened this issue Jun 8, 2023 · 12 comments
Closed

OverflowError: mktime argument out of range #275

balihb opened this issue Jun 8, 2023 · 12 comments
Labels
bug Something isn't working

Comments

@balihb
Copy link

balihb commented Jun 8, 2023

Trying to use the following schema URL:

https://raw.githubusercontent.com/microsoft/AI/master/.ci/listing_config_schema.json

Gives the following error on the 2nd run:

Error: Unexpected Error building schema validator
OverflowError: mktime argument out of range
  in "C:\Users\balihb\.cache\pre-commit\repos2k4wtzx\py_env-python3.11\Lib\site-packages\check_jsonschema\checker.py", line 52
  >>> return self._schema_loader.get_validator(
@sirosen sirosen added bug Something isn't working upstream-schema-issue An issue with a schema or schema provider labels Jun 9, 2023
@sirosen
Copy link
Member

sirosen commented Jun 9, 2023

Thanks for the bug report!

I wasn't able to reproduce this. In fact, I'm not able to use that schema at all, as it does not appear to be a valid JSON Schema. Checking it with --check-metaschema fails with a long list of errors.

Maybe the schema has changed between the time of your report and my test? I don't have a lot of bandwidth to look into this right now, but if the schema is valid, that would mean something is wrong with the validation currently done under --check-metaschema.

@balihb
Copy link
Author

balihb commented Jun 9, 2023 via email

@sirosen
Copy link
Member

sirosen commented Jun 9, 2023

I was trying on Windows. might it be a problem with platform support?

It shouldn't be, but also it shouldn't fail at all so I'm remaining open-minded. 😉

Could you post the results of running one of the failing commands with --traceback-mode full?
My current suspicion is that something is amiss with the handling of Last-Modified times for file downloads, but it's not something I've seen before, so I need a bit more info to track it down.

@sirosen sirosen removed the upstream-schema-issue An issue with a schema or schema provider label Jun 9, 2023
@balihb
Copy link
Author

balihb commented Jun 9, 2023 via email

@kurtmckee
Copy link

@balihb I have seen OverflowError pop up with datetime operations on Windows when it's a 32-bit version of Python. Would you run the following to help identify whether this is 32-bit or 64-bit Python?

python -c "import sys; print(sys.version)"

That should help focus the troubleshooting effort, by either identifying -- or eliminating -- one possible cause for that OverflowError. Thanks!

@balihb
Copy link
Author

balihb commented Jun 9, 2023 via email

@kurtmckee
Copy link

Thanks @balihb, and have a great weekend!

@balihb
Copy link
Author

balihb commented Jun 13, 2023

ok, I have two solution:

    def _lastmod_from_response(self, response: requests.Response) -> float:
        if "last-modified" in response.headers:
            return time.mktime(
                time.strptime(
                    response.headers.get("last-modified"),
                    self._LASTMOD_FMT,
                )
            )
        else:
            return time.mktime(time.gmtime(2*86400)) - 2*86400

but I think this should be enough:

    def _lastmod_from_response(self, response: requests.Response) -> float:
        if "last-modified" in response.headers:
            return time.mktime(
                time.strptime(
                    response.headers.get("last-modified"),
                    self._LASTMOD_FMT,
                )
            )
        else:
            return 0

@balihb
Copy link
Author

balihb commented Jun 13, 2023

similar issue I've found:
neo4j/neo4j-python-driver#302
also from the time doc:
The earliest date for which it can generate a time is platform-dependent.

@balihb
Copy link
Author

balihb commented Jun 13, 2023

@sirosen
Copy link
Member

sirosen commented Jun 13, 2023

Thanks for running this issue down and sharing your research!

@kurtmckee and I chatted about this a little bit, and I'm going to take a slightly different approach to fixing this, using try-except to handle a few different cases.

I'll post a PR shortly, so you'll be able to see the fix with tests, but the additional scenarios we wanted to handle include:

  • Last-Modified was present but malformed (unparseable)
  • Last-Modified was present with a value which triggers the OverflowError

@balihb, I'll make sure to credit you for your work in the changelog! 👍

@sirosen
Copy link
Member

sirosen commented Jun 13, 2023

This should be fixed in v0.23.2 which I just released.

Please let me know if you still see this problem or run into other issues!

@sirosen sirosen closed this as completed Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants