Skip to content

Commit

Permalink
avoid infinite recursion on unkown attribute access in GenericActors. (
Browse files Browse the repository at this point in the history
…#647)

* fix: avoid infinite recursion on attribute access in GenericActors.

this was triggered by sphinx autodoc use of inspect.signature that tried to
access the missing `__signature__` attribute on GenericActors

* style: fix linter errors
  • Loading branch information
CaselIT authored Aug 28, 2024
1 parent 9ac9b26 commit 4851506
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

import alabaster # noqa

import dramatiq # noqa

sys.path.insert(0, os.path.abspath('../..'))
sys.path.insert(0, os.path.abspath('./'))

import dramatiq # noqa


# -- General configuration ------------------------------------------------

Expand Down
3 changes: 3 additions & 0 deletions dramatiq/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def __new__(metacls, name, bases, attrs):
return clazz

def __getattr__(cls, name):
if "__actor__" not in cls.__dict__:
# avoid infinite recursion on GenericActor
raise AttributeError(f"type object {cls.__name__!r} has no attribute {name!r}")
return getattr(cls.__actor__, name)


Expand Down
5 changes: 5 additions & 0 deletions tests/test_generic_actors.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,8 @@ def perform(self):

# And the actor registry should be called with CustomActor
actor_registry.assert_called_once_with(CustomActor)


def test_getattr_generic_actor():
with pytest.raises(AttributeError):
dramatiq.GenericActor.missing_property

0 comments on commit 4851506

Please sign in to comment.