cache_time handling in operations.apt module broken in pyinfra v1.4
See original GitHub issueDescribe the bug
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.
To Reproduce
Steps to reproduce the behavior (include code & usage example):
Sample code (in file cache_time_test.py)
from pyinfra.operations import apt
SUDO = True
apt.update(name='This will succeed')
apt.update(name='This will fail', cache_time=3600)
Result
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
Expected behavior
Code should run to completion, updating the apt cache once, then giving ‘apt is already up to date’ result.
Meta
-
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.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
Cool! Can’t wait to give it a try. Thanks!
My pleasure. Glad to contribute to this great project.