Skip to content

Commit

Permalink
Fix TypeError when using this debug
Browse files Browse the repository at this point in the history
We need to make a copy of locals() from the method
level as inside the list comprehension its value change
and we lose access to method's arguments and their
values.

Thanks to Ben Roberts for reporting the issue!
  • Loading branch information
gdubicki committed Nov 22, 2021
1 parent 49952ac commit f5dead9
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions pypuppetdb/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,12 @@ def _query(self, endpoint=None, path=None, query=None,
:rtype: :obj:`dict` or :obj:`list`
"""

log.debug("_query called with ",
# inside the list comprehension the locals() value change so we need a function's local() copy
function_locals = locals().copy()
log.debug("_query called with: " +
# comma-separated list of method arguments with their values
", ".join([f"{arg}: {locals().get(arg, 'None')}"
for arg in locals().keys() if arg != 'self'])
", ".join([f"{arg}={function_locals.get(arg, 'None')}"
for arg in function_locals.keys() if arg != 'self'])
)

if not endpoint:
Expand Down

0 comments on commit f5dead9

Please sign in to comment.