mmerickel / wired

A service locator implementation for Python.
https://wired.readthedocs.io
MIT License
17 stars 9 forks source link

Caching issue #12

Closed enkidulan closed 5 years ago

enkidulan commented 5 years ago

Seems like a bug to me.

Set up code

# registering two factories, one without context and another with a context
registry.register_factory(factory_a, DummyFactory)
registry.register_factory(factory_b, DummyFactory, context=ContextB)

Scenario 1, works fine:

# getting factories from a container, all as expected 
assert container.get(DummyFactory, context=context_b) is factory_b.result
assert container.get(DummyFactory) is factory_a.result

Scenario 2, returns factory_a instead of factory_b:

# seccond assertion fails because of `factory_a` is returned
assert container.get(DummyFactory) is factory_a.result
assert container.get(DummyFactory, context=context_b) is factory_b.result

Tests for this issue can be found in PR https://github.com/mmerickel/wired/pull/11.

mmerickel commented 5 years ago

Agreed, looks like a bug in the caching.