Using the 'cache_time' argument in apt.update() or apt.packages() causes deploy to fail with an unexpected exception.
This started after updating to pyinfra v1.4. Before that the same code ran without error.
Steps to reproduce the behavior (include code & usage example):
from pyinfra.operations import apt
SUDO = True
apt.update(name='This will succeed')
apt.update(name='This will fail', cache_time=3600)
Running above code with only the first apt.update statement present (second statement commented out), apt is updated normally on host.
Running the code with 'apt.update(cache_time=3600)' gives the output below.
Output excerpt (personal details replaced with [...]):
--> Preparing operations...
Loading: cache_time_test.py
--> An unexpected exception occurred in: cache_time_test.py:
File "[...]/site-packages/pyinfra_cli/util.py", line 55, in exec_file
exec(PYTHON_CODES[filename], data)
File "cache_time_test.py", line 8, in <module>
apt.update(name='This will fail', cache_time=3600)
File "[...]/site-packages/pyinfra/api/operation.py", line 365, in decorated_func
commands = unroll_generators(func(*actual_args, **actual_kwargs))
File "[...]/site-packages/pyinfra/api/util.py", line 192, in unroll_generators
for item in generator:
File "[...]/site-packages/pyinfra/operations/apt.py", line 313, in update
cache_info['mtime'] = datetime.utcnow()
TypeError: 'NoneType' object does not support item assignment
Code should run to completion, updating the apt cache once, then giving 'apt is already up to date' result.
Include output of pyinfra --support.
System: Linux
Platform: Linux-5.8.0-50-generic-x86_64-with-glibc2.31
Release: 5.8.0-50-generic
Machine: x86_64
pyinfra: v1.4
Executable: /path/to/venv/bin/pyinfra
Python: 3.9.2 (CPython, GCC 9.3.0)
How was pyinfra installed (source/pip)?
pyinfra installed via pip into a venv
Include pyinfra-debug.log (if one was created)
No debug log created
Consider including output with -vv and --debug.
I didn't think this added much except that the exception occurred right after "Loaded fact date". After that the output is the same as above.
After playing around a bit, I discovered that the code runs with 'cache_time=0'. Any value >0 causes the error (as do negative integers). Only 0 works.
Thank you for spotting this @Pimmelton! Going to test / fix this ASAP!
Thank you for spotting this @Pimmelton! Going to test / fix this ASAP!
My pleasure. Glad to contribute to this great project.
I've fixed this in https://github.com/Fizzadar/pyinfra/commit/0ab90dde09e5e373a416dbd1740b5acf5ddbeded and just released v1.4.1!
Cool! Can't wait to give it a try. Thanks!