Fix fo() backdoor command for non-class objects

The backdoor command fo() uses isinstance() to check if an object is an
instance of a class. This only works with objects that have a __class__
attribute, else an AttributeError is raised by isinstance(). This is
seldomly the case, though if there is one such object fo() will cease to
work. Therefore we need to protect us against this case by checking for
a __class__ attribute before calling isinstance().

An example for an object without __class__ would be
functools._lru_list_elem.

Change-Id: Ia4c5cbdc249535d36f6e71f7b2a7359bc6fdf219
Closes-Bug: #1946072
This commit is contained in:
Sebastian Lohff 2021-07-14 12:37:49 +02:00 committed by Stephen Finucane
parent 091fd6510a
commit eb191548cf
2 changed files with 8 additions and 1 deletions

View File

@ -86,7 +86,8 @@ def _detailed_dump_frames(f, thread_index):
def _find_objects(t):
return [o for o in gc.get_objects() if isinstance(o, t)]
return [o for o in gc.get_objects()
if hasattr(o, "__class__") and isinstance(o, t)]
def _capture_profile(fname=''):

View File

@ -0,0 +1,6 @@
---
fixes:
- |
Fix the backdoor helper method fo() to also work when there are objects
present in the current python instance that do not have a __class__
attribute.