Skip to content

fix(ingestion): build_patch crashes on EntityReferenceList fields in array_entity_fields #32008

Closed

Description

@zak-nuccio

Problem

_sort_array_entity_fields in patch_request.py crashes with AttributeError: 'list' object has no attribute 'root' when any EntityReferenceList-typed field (e.g. domains, dataProducts) is passed in array_entity_fields.

Two issues in the same function:

  1. Iterating a RootModel yields tuples, not items — pydantic v2 RootModel iteration yields (key, value) tuples, so _get_attribute_name and __dict__ access both fail.
  2. setattr with a plain list breaks serialization — replacing a RootModel field with a bare list causes subsequent model_dump_json calls to crash because pydantic expects the RootModel wrapper.

This affects anyone calling metadata.patch() with array_entity_fields containing EntityReferenceList-typed fields (e.g. dataProducts, domains, owners, reviewers).

Reproduction

from metadata.generated.schema.entity.data.table import Table
from metadata.generated.schema.type.entityReference import EntityReference
from metadata.generated.schema.type.entityReferenceList import EntityReferenceList
from metadata.ingestion.models.patch_request import build_patch
import uuid

source = Table(id=str(uuid.uuid4()), name='t', columns=[], fullyQualifiedName='svc.db.schema.t')
source.dataProducts = EntityReferenceList(root=[])
dest = source.model_copy(deep=True)
dest.dataProducts = EntityReferenceList(root=[EntityReference(id=str(uuid.uuid4()), type='dataProduct', name='dp1')])

build_patch(source=source, destination=dest, array_entity_fields=['dataProducts'])
# RuntimeError: Failed to build patch. Error: 'list' object has no attribute 'root'

Fix

In _sort_array_entity_fields:

  • Extract .root before iterating RootModel fields
  • Re-wrap via model_copy(update={"root": ...}) instead of setting a bare list

PR: https://github.com/open-metadata/OpenMetadata/pull/NNNN

Tests

  • test_empty_to_populated_data_products — the original crash case
  • test_replace_data_products — swapping one dataProduct for another
  • test_same_data_products_no_patch — identical values produce no patch
  • test_empty_to_populated_domains — same pattern for domains
  • test_both_domains_and_data_products — both fields in one call
  • test_no_array_entity_fields_still_works — non-arrayEntityFields path unaffected

Activity

  1. added theissue type on Aug 26, 2026
  2. added
    bug
    on Aug 26, 2026
  3. added this to Shipping and removed this from Roadmapon Aug 26, 2026
  4. moved this to In Review / QA 👀 in Shippingon Aug 26, 2026
  5. self-assigned this
    on Aug 27, 2026
  6. moved this from In Review / QA 👀 to Done ✅ in Shippingon Aug 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

Projects

  • Status
    Done ✅

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions