larq/zookeeper

`__getattribute__` can incorrectly call `build()` on factory instances

AdamHillier opened this issue · 0 comments

Implicit calling of build() is desired behaviour when accessing a field, but the current behaviour is for this to happen always, including e.g. when accessing instance.__component_parent__, as is frequently done internally. This is incorrect behaviour, and causes failures with confusing error messages (and sometimes infinite recursion). The behaviour in question comes from here:

@functools.wraps(base_wrapped_fn)
def wrapped_fn(instance, name):
result = base_wrapped_fn(instance, name)
if utils.is_factory_instance(result):
return result.build()
return result

We need to check that name is a valid field name before calling build() implicitly.

Apologies to @timdebruin for this bug....