Skip to content

Issue #1008: name-based portable export serializer#1

Open
bjagg wants to merge 1 commit into
fix/issue-668-mdr-import-servicefrom
feat/mdr-portable-export-serializer
Open

Issue #1008: name-based portable export serializer#1
bjagg wants to merge 1 commit into
fix/issue-668-mdr-import-servicefrom
feat/mdr-portable-export-serializer

Conversation

@bjagg

@bjagg bjagg commented Jun 23, 2026

Copy link
Copy Markdown
Owner

Stacked on LIF-Initiative#1006. Base is fix/issue-668-mdr-import-service so the diff is just this one commit. The round-trip relies on the LIF-Initiative#668 import fixes. Retarget to upstream main once LIF-Initiative#1006 merges.

Description of Change

POST /import/ (import_datamodel) consumes a name-based ImportDataModelDTO — cross-row references are expressed as names, the portable identity that survives across installs. But GET /export/{id} emits ID-based DTOs whose references are the source database's primary keys (artifacts meaningless in another install). The two never matched, so the documented export → import round-trip could not run.

Solution. Add build_import_data_model_dto(), which rewrites every reference in an export — EntityId, AttributeId, ValueSetId, ParentEntityId/ChildEntityId, the constraint ElementId, and each attribute's owning entity (resolved via the entity/attribute association) — as the referenced row's name, and drops source-DB artifacts (row ids, BaseDataModelId, value OriginalValueId). Expose it as export_datamodel_portable() / GET /export/portable/{data_model_id}, returning a payload ready to POST straight back to /import/.

Also fixes get_export_dto, which passed a non-existent check_base kwarg to get_list_of_entities_for_data_model and get_entity_associations_by_data_model_id — both raised TypeError, so the export path never returned anything.

Side effects / limitations.

  • Scope is a single data model (SourceSchema / standalone). OrgLIF/PartnerLIF extended models whose elements span a separate base model are not handled — import_datamodel takes a single DTO and the base/extended split needs its own design (follow-up).
  • Transformations (mappings) are still not carried (MDR Transformation Portability: Expose the export transformation group endpoint LIF-Initiative/lif-core#771).
  • export_multiple_datamodel has a separate pre-existing bug (unpacks 6 of get_export_dto's 7 return values); left untouched as out of scope.

How reviewers should test. uv run pytest test/bases/lif/mdr_restapi/test_portable_export_roundtrip.py — an end-to-end Postgres round-trip: seed a source model (2 entities, 2 attributes incl. one with a value set, an entity reference, a data-model constraint) → export_datamodel_portableimport_datamodel → assert every reference survives as a name (attribute→entity, value-set name, parent→child association with relationship, constraint element + remapped ForDataModelId).

Related Issues

Closes LIF-Initiative#1008

Type of Change
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
Project Area(s) Affected
  • components/
  • bases/
  • API endpoints
  • test/ or e2e/

Checklist
  • commit message follows commit guidelines (see commitlint.config.mjs)
  • tests are included (unit and/or integration tests)
  • code passes linting checks (uv run ruff check)
  • code passes formatting checks (uv run ruff format)
  • code passes type checking (uv run ty check) — no new diagnostics introduced
  • pre-commit hooks have been run successfully
Testing
  • Automated tests added/updated (end-to-end Postgres round-trip)
Additional Notes

Full mdr_services unit suite + the new round-trip pass (94 tests); ruff/format clean; ty diagnostics unchanged vs the base branch (18→17). New endpoint GET /export/portable/{data_model_id} returns ImportDataModelDTO.

🤖 Generated with Claude Code

The export side emits ID-based DTOs whose cross-row references are the source
database's primary keys, while import_datamodel consumes a name-based
ImportDataModelDTO. The two never matched, so the export -> import round-trip
could not run.

Add build_import_data_model_dto(), which rewrites every reference in an export
(EntityId, AttributeId, ValueSetId, ParentEntityId/ChildEntityId, constraint
ElementId, and an attribute's owning entity via the entity/attribute
association) as the referenced row's name, and drops source-DB artifacts (row
ids, BaseDataModelId, value OriginalValueId). Expose it as
export_datamodel_portable() / GET /export/portable/{id}, returning a payload
ready to POST straight back to /import/.

Also fix get_export_dto, which passed a non-existent check_base kwarg to
get_list_of_entities_for_data_model and get_entity_associations_by_data_model_id
(both raised TypeError, so the export path never returned).

Scope: a single data model (SourceSchema / standalone). OrgLIF/PartnerLIF
extended models spanning a base model, and transformations (LIF-Initiative#771), are
follow-ups. Adds an end-to-end Postgres round-trip test covering entities,
attribute->entity resolution, value-set name resolution, entity associations,
and constraints.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant