Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recursion Error during injection #824

Open
jamesra opened this issue Oct 17, 2024 · 1 comment
Open

Recursion Error during injection #824

jamesra opened this issue Oct 17, 2024 · 1 comment

Comments

@jamesra
Copy link

jamesra commented Oct 17, 2024

I'm getting a recursion error when an object is instantiated using an overridden container with this rough form. Any thoughts on what the cause might be?

I'm new to dependency injection so I hope the structure is correct. I have a window that displays a transformed image, and I want the mouse to behave differently depending on the type of transform.

class ControlPointAction(enum.Flag):
    """Possible interactions for control point(s)"""
    NONE = 0
    CREATE = 1
    DELETE = 2
    TRANSLATE = 4

class TransformType(enum.Enum): 
    RIGID = 'Rigid'
    GRID = 'Grid'
    MESH = 'Mesh'
    RBF = 'RBF'


ControlPointActionCommandMapType = Dict[ControlPointAction, Factory[ICommand]]

class Container(containers.DeclarativeContainer):
# We want a different set of transform commands for each type of transform
    action_command_map = providers.Dependency(
        instance_of=providers.Dict[TransformType, ControlPointActionCommandMapType])

@containers.override(Container)
class StosContainer(containers.DeclarativeContainer):
    action_command_map = providers.Dict[TransformType, ControlPointActionCommandMapType]({
        TransformType.GRID: providers.Dict({
            ControlPointAction.NONE: providers.Factory(DefaultTransformCommand),
            ControlPointAction.TRANSLATE: providers.Factory(TranslateControlPointCommand),
        }),
        TransformType.MESH: providers.Dict({
            ControlPointAction.NONE: providers.Factory(DefaultTransformCommand),
            ControlPointAction.TRANSLATE: providers.Factory(TranslateControlPointCommand),
        }),
        TransformType.RBF: providers.Dict({
            ControlPointAction.NONE: providers.Factory(DefaultTransformCommand),
            ControlPointAction.TRANSLATE: providers.Factory(TranslateControlPointCommand),
        }),
        TransformType.RIGID: providers.Dict({
            ControlPointAction.NONE: providers.Factory(DefaultTransformCommand),
            ControlPointAction.TRANSLATE: providers.Factory(TranslateControlPointCommand),
        })
    })


class Command:
   @inject
   def __init__(transform_type_to_command_action_map: Dict[TransformType, ControlPointActionCommandMapType] = Provide[Container.action_command_map]):
   """Infinite recursion occurs when constructor is invoked"""
        pass
  
Original exception was:
object address  : 000001FE1B806CE0
object refcount : 2
object type     : 00007FFE0495A730
object type name: RecursionError
object repr     : 
lost sys.stderr
Traceback (most recent call last):
  File "src/dependency_injector/providers.pxd", line 445, in dependency_injector.providers.__provide_keyword_args
  File "src/dependency_injector/providers.pxd", line 365, in dependency_injector.providers.__get_value
  File "src/dependency_injector/providers.pyx", line 225, in dependency_injector.providers.Provider.__call__
  File "src/dependency_injector/providers.pyx", line 2689, in dependency_injector.providers.Factory._provide
  File "src/dependency_injector/providers.pxd", line 650, in dependency_injector.providers.__factory_call
  File "src/dependency_injector/providers.pxd", line 608, in dependency_injector.providers.__call
  File "src/dependency_injector/_cwiring.pyx", line 26, in dependency_injector._cwiring._get_sync_patched._patched
  File "src/dependency_injector/providers.pyx", line 811, in dependency_injector.providers.Dependency.__call__
  File "src/dependency_injector/providers.pyx", line 225, in dependency_injector.providers.Provider.__call__
  File "src/dependency_injector/providers.pyx", line 3634, in dependency_injector.providers.Dict._provide
  File "src/dependency_injector/providers.pxd", line 445, in dependency_injector.providers.__provide_keyword_args
  File "src/dependency_injector/providers.pxd", line 365, in dependency_injector.providers.__get_value
  File "src/dependency_injector/providers.pyx", line 225, in dependency_injector.providers.Provider.__call__
  File "src/dependency_injector/providers.pyx", line 3634, in dependency_injector.providers.Dict._provide
  File "src/dependency_injector/providers.pxd", line 445, in dependency_injector.providers.__provide_keyword_args
  File "src/dependency_injector/providers.pxd", line 365, in dependency_injector.providers.__get_value
  File "src/dependency_injector/providers.pyx", line 225, in dependency_injector.providers.Provider.__call__
  File "src/dependency_injector/providers.pyx", line 2689, in dependency_injector.providers.Factory._provide
  File "src/dependency_injector/providers.pxd", line 650, in dependency_injector.providers.__factory_call
  File "src/dependency_injector/providers.pxd", line 608, in dependency_injector.providers.__call
  File "src/dependency_injector/_cwiring.pyx", line 26, in dependency_injector._cwiring._get_sync_patched._patched
  File "src/dependency_injector/providers.pyx", line 811, in dependency_injector.providers.Dependency.__call__
  File "src/dependency_injector/providers.pyx", line 225, in dependency_injector.providers.Provider.__call__
  File "src/dependency_injector/providers.pyx", line 3634, in dependency_injector.providers.Dict._provide
  File "src/dependency_injector/providers.pxd", line 445, in dependency_injector.providers.__provide_keyword_args
  File "src/dependency_injector/providers.pxd", line 365, in dependency_injector.providers.__get_value
  File "src/dependency_injector/providers.pyx", line 225, in dependency_injector.providers.Provider.__call__
  File "src/dependency_injector/providers.pyx", line 3634, in dependency_injector.providers.Dict._provide
  File "src/dependency_injector/providers.pxd", line 445, in dependency_injector.providers.__provide_keyword_args
  File "src/dependency_injector/providers.pxd", line 365, in dependency_injector.providers.__get_value
  File "src/dependency_injector/providers.pyx", line 225, in dependency_injector.providers.Provider.__call__
  File "src/dependency_injector/providers.pyx", line 2689, in dependency_injector.providers.Factory._provide
  File "src/dependency_injector/providers.pxd", line 650, in dependency_injector.providers.__factory_call
  File "src/dependency_injector/providers.pxd", line 608, in dependency_injector.providers.__call
  File "src/dependency_injector/_cwiring.pyx", line 26, in dependency_injector._cwiring._get_sync_patched._patched
  File "src/dependency_injector/providers.pyx", line 811, in dependency_injector.providers.Dependency.__call__
  File "src/dependency_injector/providers.pyx", line 225, in dependency_injector.providers.Provider.__call__
  File "src/dependency_injector/providers.pyx", line 3634, in dependency_injector.providers.Dict._provide
  File "src/dependency_injector/providers.pxd", line 445, in dependency_injector.providers.__provide_keyword_args
  File "src/dependency_injector/providers.pxd", line 365, in dependency_injector.providers.__get_value
  ...
@jamesra
Copy link
Author

jamesra commented Oct 17, 2024

Version of dependency-injector is 4.42
Python 3.11.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant