Skip to content

CSV recursive import wipes table constraints (primary key / unique / foreign key) #31857

Description

@sonika-shah

Affects

  • Reproduced on 1.12.14 and on main / 2.0 (server 2.0.0). Not fixed by upgrading.

Summary

A recursive CSV import of a Database Service / Database / Database Schema silently wipes all table constraints (PRIMARY KEY, UNIQUE, and FOREIGN KEY relationships) on every table it processes, even though constraints are never represented in the CSV.

This is user-reachable from the UI: the Manage (⋮) → Export/Import on a Service / Database / Schema page issues importAsync?...&recursive=true, so a normal parent-level re-import in the UI drops constraints.

Steps to reproduce

  1. Create a table with tableConstraints (e.g. a PRIMARY_KEY on id, a UNIQUE on email, and a FOREIGN_KEY on a column referring to another table's column).
  2. Export the parent Database Schema (or Database / Service) recursively:
    GET /api/v1/databaseSchemas/name/{fqn}/export?recursive=true
  3. Re-import it unchanged:
    PUT /api/v1/databaseSchemas/name/{fqn}/import?dryRun=false&recursive=true
  4. Fetch the table: GET /api/v1/tables/name/{fqn}?fields=tableConstraints.

Expected

tableConstraints unchanged (nothing in the CSV should have removed them).

Actual

tableConstraints is empty [] — PK, UNIQUE, and FK all lost.

Root cause

EntityCsv.createTableEntity(...) (openmetadata-service .../csv/EntityCsv.java) fetches the existing table with a field set that omits tableConstraints:

table = getEntityWithDependencyResolution(
    TABLE, tableFqn, "owners,tags,domains,extension", Include.NON_DELETED);

It then populates table-level fields from the CSV row and calls createEntity(...)repository.createOrUpdate(...). Because tableConstraints was never loaded, the persisted table has tableConstraints = null, so the existing constraints are removed. (The recursive CSV has no constraints column, so they are not re-added.)

Suggested fix

Include tableConstraints (and tablePartition) in the createTableEntity fetch so they carry through the createOrUpdate unchanged. A regression test should assert that a recursive export→import round trip preserves PK/UNIQUE/FK.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions