Error when configuring components with values inherited from factories
AdamHillier opened this issue · 0 comments
AdamHillier commented
The following fails:
@factory
class IntFactory:
def build(self) -> int:
return 5
@component
class Child:
x: int = ComponentField()
@component
class Parent:
child: Child = ComponentField(Child)
x: int = ComponentField(IntFactory)
p = Parent()
configure(p, {})
assert p.x == 5
assert p.child.x == 5
with error AttributeError: 'int' object has no attribute '__component_configured__'
.
This happens because configure()
tries to recursively configure p.child.x
, as it is a ComponentField
(shadowing p.x
, which is a ComponentField
). But p.child.x
resolves to an integer. We can solve this by checking that the thing we try and recursively configure is a component instance (this will not break type-checking, which happens separately).