pyinfra icon indicating copy to clipboard operation
pyinfra copied to clipboard

Large `cache_time` value to `files.download` causes OverflowError exception

Open link2xt opened this issue 5 months ago • 1 comments

We used cache_time=9999999999999 to effectively disable redownloading of the file which is supposed to never change. The file downloaded on a first time, but on a second time pyinfra crashed with the exception:

-​-> An internal exception occurred:

  File "/home/*********/relay/venv/lib/python3.11/site-packages/pyinfra/operations/files.py", line 129, in download
    ctime = host.get_fact(Date).replace(tzinfo=None) - timedelta(seconds=cache_time)
    ^^^^^^^^^^^^^^^^^
OverflowError: date value out of range

-​-> The full traceback has been written to pyinfra-debug.log

One way to fix it would be to handle the underflow and assume that the cache has not expired if there is an underflow.

Another option that would have helped us is to not redownload the file if checksum is specified and the file with the correct checksum is already there. This would be preferable for our usecase, then we would not need to specify cache_time at all.

See https://github.com/chatmail/relay/issues/602 for downstream issue.

link2xt avatar Jul 08 '25 19:07 link2xt

seems like it's caused by the calculation breaking the 32bit limit (even assuming it's unsigned)

Image (this is the value used in the case of deltachat)

fluoriteByte avatar Jul 08 '25 19:07 fluoriteByte