OpenMetadata icon indicating copy to clipboard operation
OpenMetadata copied to clipboard

[Bug] OpenLineageEntityResolver does not set updatedAt/updatedBy on auto-created entities — breaks PostgreSQL

Open kmush12 opened this issue 7 months ago • 3 comments

Affected module Backend — OpenLineageEntityResolver (server-side OpenLineage REST API consumer at POST /api/v1/openlineage/lineage). Affects entity auto-creation for both Pipeline and Table entities when processing incoming OpenLineage RunEvents.

Describe the bug When OpenMetadata receives an OpenLineage RunEvent referencing a pipeline or table that does not yet exist, the OpenLineageEntityResolver attempts to auto-create the entity. Both createPipeline() and createTableInternal() accept an updatedBy parameter from the caller but never apply it to the entity object. They call repository.create(null, entity) (2-arg overload), which routes to createInternal(entity, null, null) and leaves updatedAt and updatedBy null in the JSON blob.

On PostgreSQL, these are generated stored columns with NOT NULL constraints:

updatedat bigint GENERATED ALWAYS AS (((json ->> 'updatedAt'::text))::bigint) STORED NOT NULL
updatedby varchar(256) GENERATED ALWAYS AS ((json ->> 'updatedBy'::text)) STORED NOT NULL

The INSERT fails:

ERROR: null value in column "updatedat" of relation "pipeline_entity" violates not-null constraint
Detail: Failing row contains (..., null, null).

The error is silently caught — the API returns 200 OK with "Event processed, no lineage edges created", but the pipeline entity is never persisted. Server logs show:

ERROR [dw-359 - POST /api/v1/openlineage/lineage] o.o.s.o.OpenLineageEntityResolver -
  Failed to create pipeline openlineage-test_nonexistent_pipeline:
  org.postgresql.util.PSQLException: ERROR: null value in column "updatedat" of relation "pipeline_entity"
  violates not-null constraint

The actual JSON blob written to PostgreSQL confirms the missing fields:

{"id":"b2233ae7-...","name":"openlineage-test_nonexistent_pipeline",
 "fullyQualifiedName":"openlineage.openlineage-test_nonexistent_pipeline",
 "description":"Pipeline created from OpenLineage event",
 "version":0.1,"serviceType":"OpenLineage","deleted":false,"entityStatus":"Unprocessed"}

No updatedAt, no updatedBy.

On MySQL the same columns are VIRTUAL instead of STORED, so the constraint is not enforced at INSERT time and the bug is silently hidden.

To Reproduce

  1. Deploy OpenMetadata 1.12.5 with PostgreSQL as the metadata store
  2. Create a Pipeline Service of type OpenLineage via the API:
    curl -X POST http://<om-host>:8585/api/v1/services/pipelineServices \
      -H "Authorization: Bearer <token>" \
      -H "Content-Type: application/json" \
      -d '{"name":"openlineage","serviceType":"OpenLineage","connection":{"config":{"type":"OpenLineage"}}}'
    
  3. Ensure OpenLineage settings have autoCreateEntities: true (default) and defaultPipelineService matches the service name from step 2
  4. Send an OpenLineage RunEvent referencing a pipeline that does not yet exist:
    curl -X POST http://<om-host>:8585/api/v1/openlineage/lineage \
      -H "Authorization: Bearer <token>" \
      -H "Content-Type: application/json" \
      -d '{
        "schemaURL": "https://openlineage.io/spec/2-0-2/OpenLineage.json#/definitions/RunEvent",
        "eventType": "COMPLETE",
        "eventTime": "2026-04-20T14:00:00.000Z",
        "run": { "runId": "00000000-0000-0000-0000-000000000099" },
        "job": { "namespace": "openlineage", "name": "test_nonexistent_pipeline" },
        "inputs": [{ "namespace": "openlineage", "name": "test_db.test_schema.input_table" }],
        "outputs": [{ "namespace": "openlineage", "name": "test_db.test_schema.output_table" }],
        "producer": "https://github.com/OpenLineage/OpenLineage/tree/1.28.0/integration/spark"
      }'
    
  5. API returns 200 OK with "Event processed, no lineage edges created" — misleading success
  6. Observe constraint violation in OpenMetadata server logs
  7. Verify pipeline was NOT created: GET /api/v1/pipelines?service=openlineage returns 0 results

Expected behavior OpenLineageEntityResolver should set updatedAt and updatedBy on newly created entities before persisting them, consistent with initializeEntity() in EntityRepository.java:

entity.setUpdatedBy(ADMIN_USER_NAME);
entity.setUpdatedAt(System.currentTimeMillis());
entity.setId(UUID.randomUUID());
create(null, entity);

Suggested fix — in OpenLineageEntityResolver.java, before each repository.create(null, entity) call:

// createPipeline() — around line 656
newPipeline.setUpdatedBy(updatedBy);
newPipeline.setUpdatedAt(System.currentTimeMillis());

// createTableInternal() — around line 451
newTable.setUpdatedBy(updatedBy);
newTable.setUpdatedAt(System.currentTimeMillis());

Alternatively, use the 4-arg create(uriInfo, entity, updatedBy, impersonatedBy) overload which handles updatedBy internally (but updatedAt still needs to be set on the entity).

Version:

  • OS: Linux (Kubernetes 1.32, minikube single-node)
  • Python version: N/A (Java backend bug)
  • OpenMetadata version: 1.12.5 (also confirmed on main branch — code unchanged)
  • OpenMetadata Ingestion package version: N/A (server-side entity resolver, not ingestion framework)

Additional context

  • Tested and reproduced on: OpenMetadata 1.12.5, PostgreSQL 16.1.0 (Bitnami Helm chart), OpenLineage Spark agent io.openlineage:openlineage-spark_2.13:1.28.0, Apache Spark 4.0.2, JDK 17
  • Bug introduced in PR #24686 (OpenLineage compatible APIs, merged Dec 8, 2025)
  • Integration tests in OpenLineageLineageResolutionIT.java pre-create all entities via the REST API — auto-create code path is never exercised against a real database
  • Unit tests in OpenLineageEntityResolverTest.java use Mockito mocks and do not catch the missing fields
  • The updatedBy parameter is passed through multiple call layers (resolveOrCreatePipeline -> createPipeline) but never applied to the entity — this is an oversight, not a design choice
  • Bug occurs consistently on every first OpenLineage event referencing a new entity
  • MySQL hides this bug because VIRTUAL generated columns don't enforce NOT NULL at INSERT time

Spark composite transport configuration used during testing:

spark.openlineage.transport.type=composite
spark.openlineage.transport.continueOnFailure=true
spark.openlineage.transport.transports.marquez.type=http
spark.openlineage.transport.transports.marquez.url=http://ilum-marquez:9555
spark.openlineage.transport.transports.marquez.endpoint=/api/v1/lineage
spark.openlineage.transport.transports.openmetadata.type=http
spark.openlineage.transport.transports.openmetadata.url=http://ilum-openmetadata:8585
spark.openlineage.transport.transports.openmetadata.endpoint=/api/v1/openlineage/lineage
spark.openlineage.transport.transports.openmetadata.auth.type=api_key
spark.openlineage.transport.transports.openmetadata.auth.apiKey=<jwt-token>

kmush12 avatar Apr 20 '26 13:04 kmush12

I want to work on this issue. Please assign this to me.

miantalha45 avatar Apr 20 '26 13:04 miantalha45

Hi, I noticed this was claimed about a month ago but no PR has been opened yet. @miantalha45 are you still working on this? If not I'd like to take it up.

srinithreddy16 avatar Jun 19 '26 01:06 srinithreddy16

@srinithreddy16 assigned it to you

harshach avatar Jun 19 '26 01:06 harshach