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

providers.Object not injecting the original object #231

Closed
davidcim opened this issue Oct 7, 2019 · 6 comments

Comments

@davidcim
Copy link

commented Oct 7, 2019

In the documentation you can read about the Object provider:

Object - provider that returns provided instance "as is".

However when I try to inject a parameter from an Object provider I get a different instance. I have been only able to get the original object using a Callable provider.

This code exemplifies the issue:

from dependency_injector import containers, providers


class Obj:
    pass


my_obj = Obj()


class IocContainer(containers.DeclarativeContainer):

    obj1 = providers.Object(
        my_obj,
    )

    obj2 = providers.Callable(
        lambda: my_obj
    )


ioc = IocContainer()
print('Original object: ', my_obj)
print('providers.Object', ioc.obj1())
print('providers.Callable', ioc.obj2())

As you can see in the output, providers.Object is returning a different instance:

Original object:  <__main__.Obj object at 0x7fcc0d1e16a0>
providers.Object <__main__.Obj object at 0x7fcc0d1e17f0>
providers.Callable <__main__.Obj object at 0x7fcc0d1e16a0>

I am using Python 3.5.2 and dependency-injector 3.14.10

@rmk135 rmk135 self-assigned this Oct 8, 2019
@rmk135

This comment has been minimized.

Copy link
Member

commented Oct 8, 2019

Hello @davidcim ,

You're right, that is not expected behavior. Let me debug this...

Thanks,
Roman

@rmk135

This comment has been minimized.

Copy link
Member

commented Oct 8, 2019

Oh gosh, it creates a copy of Object provider content. That's weird and should be fixed.

Working on fix...

@rmk135 rmk135 removed the question label Oct 8, 2019
@rmk135

This comment has been minimized.

Copy link
Member

commented Oct 8, 2019

Gosh, this bug is there since 3.0.0 that was published Nov 11, 2016...

@rmk135

This comment has been minimized.

Copy link
Member

commented Oct 8, 2019

Fix is published in 3.14.11.

@davidcim , thanks a lot for reporting the issue.

Roman

@rmk135 rmk135 closed this Oct 8, 2019
@davidcim

This comment has been minimized.

Copy link
Author

commented Oct 9, 2019

@rmk135, thank you for fixing it so quickly.

@rmk135

This comment has been minimized.

Copy link
Member

commented Oct 9, 2019

@davidcim , please update to 3.14.12, see #235 for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.