question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cache_time handling in operations.apt module broken in pyinfra v1.4

See original GitHub issue

Describe 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:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Pimmeltoncommented, May 15, 2021

Cool! Can’t wait to give it a try. Thanks!

1reaction
Pimmeltoncommented, May 13, 2021

Thank you for spotting this @Pimmelton! Going to test / fix this ASAP!

My pleasure. Glad to contribute to this great project.

Read more comments on GitHub >

github_iconTop Results From Across the Web

pyinfra/CHANGELOG.md at 2.x - GitHub
v2.5.3. Fix handling of facts with no arguments or with global arguments; Fix mutable default breaking Host.loop position tracking; Cleanup exception ...
Read more >
Apt Operations — pyinfra documentation
When installing, apt-get install -f will be run to install any unmet dependencies. URL sources with present=False : If the .deb file isn't...
Read more >
Ansible 1.9.4 : Failed to lock apt for exclusive operation
The error ansible gave me was Failed to lock apt for exclusive operation: ... yes do any good. become is a parameter for...
Read more >
pyinfra - PyPI
ad-hoc command execution, service deployment, configuration management and more ... from pyinfra.operations import apt apt.packages( name="Ensure iftop is ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found