diff --git a/zookeeper/core/component.py b/zookeeper/core/component.py
index aa248b9..8ce0517 100644
--- a/zookeeper/core/component.py
+++ b/zookeeper/core/component.py
@@ -215,7 +215,9 @@ def _wrap_getattribute(component_cls: Type) -> None:
     @functools.wraps(base_wrapped_fn)
     def wrapped_fn(instance, name):
         result = base_wrapped_fn(instance, name)
-        if utils.is_factory_instance(result):
+        if name in base_wrapped_fn(
+            instance, "__component_fields__"
+        ) and utils.is_factory_instance(result):
             return result.build()
         return result
 

`__getattribute__` can incorrectly call `build()` on factory instances
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:

https://github.com/larq/zookeeper/blob/c8eaab4bff5aaff6781617c7ec5b7eb9f04fb6d0/zookeeper/core/component.py#L215-L220

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

Apologies to @timdebruin for this bug....
diff --git a/zookeeper/core/component_test.py b/zookeeper/core/component_test.py
index 7f57380..8495571 100644
--- a/zookeeper/core/component_test.py
+++ b/zookeeper/core/component_test.py
@@ -393,6 +393,30 @@ def test_component_field_factory_type_check(capsys):
     )
 
 
+def test_component_getattr_value_via_factory_parent():
+    """See https://github.com/larq/zookeeper/issues/121."""
+
+    @component
+    class Child:
+        x: int = Field()
+
+    @factory
+    class Factory:
+        child: Child = ComponentField(Child)
+
+        x: int = Field(5)
+
+        def build(self) -> int:
+            return self.child.x
+
+    f = Factory()
+
+    configure(f, {})
+
+    assert f.child.x == 5
+    assert f.build() == 5
+
+
 def test_component_post_configure():
     with pytest.raises(
         TypeError,

pip install -e .
parse_log_pytest
requirements.txt
pytest pytest-cov pytest-flake8 pytest-catchlog
apt-get update apt-get install -y gcc
3.6
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
absl-py==0.12.0
attrs==22.2.0
certifi==2021.5.30
charset-normalizer==2.0.12
click==8.0.4
coverage==6.2
dataclasses==0.8
dill==0.3.4
flake8==5.0.4
googleapis-common-protos==1.56.3
idna==3.10
importlib-metadata==4.2.0
importlib-resources==5.4.0
iniconfig==1.1.1
mccabe==0.7.0
numpy==1.19.5
packaging==21.3
pluggy==1.0.0
promise==2.3
prompt-toolkit==3.0.36
protobuf==3.19.6
py==1.11.0
pycodestyle==2.9.1
pyflakes==2.5.0
pyparsing==3.1.4
pytest==7.0.1
pytest-catchlog==1.2.2
pytest-cov==4.0.0
pytest-flake8==1.1.1
requests==2.27.1
six==1.17.0
tensorflow-datasets==4.5.2
tensorflow-metadata==1.2.0
termcolor==1.1.0
tomli==1.2.3
tqdm==4.64.1
typeguard==2.13.3
typing_extensions==4.1.1
urllib3==1.26.20
wcwidth==0.2.13
zipp==3.6.0
-e git+https://github.com/larq/zookeeper.git@c8eaab4bff5aaff6781617c7ec5b7eb9f04fb6d0#egg=zookeeper

name: zookeeper
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=21.2.2=py36h06a4308_0
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - absl-py==0.12.0
      - attrs==22.2.0
      - charset-normalizer==2.0.12
      - click==8.0.4
      - coverage==6.2
      - dataclasses==0.8
      - dill==0.3.4
      - flake8==5.0.4
      - googleapis-common-protos==1.56.3
      - idna==3.10
      - importlib-metadata==4.2.0
      - importlib-resources==5.4.0
      - iniconfig==1.1.1
      - mccabe==0.7.0
      - numpy==1.19.5
      - packaging==21.3
      - pluggy==1.0.0
      - promise==2.3
      - prompt-toolkit==3.0.36
      - protobuf==3.19.6
      - py==1.11.0
      - pycodestyle==2.9.1
      - pyflakes==2.5.0
      - pyparsing==3.1.4
      - pytest==7.0.1
      - pytest-catchlog==1.2.2
      - pytest-cov==4.0.0
      - pytest-flake8==1.1.1
      - requests==2.27.1
      - six==1.17.0
      - tensorflow-datasets==4.5.2
      - tensorflow-metadata==1.2.0
      - termcolor==1.1.0
      - tomli==1.2.3
      - tqdm==4.64.1
      - typeguard==2.13.3
      - typing-extensions==4.1.1
      - urllib3==1.26.20
      - wcwidth==0.2.13
      - zipp==3.6.0
prefix: /opt/conda/envs/zookeeper

zookeeper/core/component_test.py::test_component_getattr_value_via_factory_parent
zookeeper/core/component_test.py::test_non_class_decorate_error zookeeper/core/component_test.py::test_abstract_class_decorate_error zookeeper/core/component_test.py::test_init_decorate_error zookeeper/core/component_test.py::test_no_init zookeeper/core/component_test.py::test_configure_override_field_values zookeeper/core/component_test.py::test_configure_scoped_override_field_values zookeeper/core/component_test.py::test_configure_automatically_instantiate_subcomponent zookeeper/core/component_test.py::test_configure_non_interactive_missing_field_value zookeeper/core/component_test.py::test_configure_interactive_prompt_missing_field_value zookeeper/core/component_test.py::test_configure_interactive_prompt_for_subcomponent_choice zookeeper/core/component_test.py::test_str_and_repr zookeeper/core/component_test.py::test_type_check zookeeper/core/component_test.py::test_error_if_field_overwritten_in_subclass zookeeper/core/component_test.py::test_component_field_factory_type_check zookeeper/core/component_test.py::test_component_post_configure zookeeper/core/component_test.py::test_component_configure_error_non_existant_key zookeeper/core/component_test.py::test_component_configure_field_allow_missing zookeeper/core/component_test.py::test_component_configure_component_field_allow_missing zookeeper/core/component_test.py::test_component_allow_missing_field_inherits_defaults
zookeeper/core/component.py
zookeeper/core/component.py