Issue #1008: name-based portable export serializer#1
Open
bjagg wants to merge 1 commit into
Open
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of Change
POST /import/(import_datamodel) consumes a name-basedImportDataModelDTO— cross-row references are expressed as names, the portable identity that survives across installs. ButGET /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 constraintElementId, 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, valueOriginalValueId). Expose it asexport_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-existentcheck_basekwarg toget_list_of_entities_for_data_modelandget_entity_associations_by_data_model_id— both raisedTypeError, so the export path never returned anything.Side effects / limitations.
import_datamodeltakes a single DTO and the base/extended split needs its own design (follow-up).export_multiple_datamodelhas a separate pre-existing bug (unpacks 6 ofget_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_portable→import_datamodel→ assert every reference survives as a name (attribute→entity, value-set name, parent→child association with relationship, constraint element + remappedForDataModelId).Related Issues
Closes LIF-Initiative#1008
Type of Change
Project Area(s) Affected
Checklist
uv run ruff check)uv run ruff format)uv run ty check) — no new diagnostics introducedTesting
Additional Notes
Full
mdr_servicesunit suite + the new round-trip pass (94 tests);ruff/format clean;tydiagnostics unchanged vs the base branch (18→17). New endpointGET /export/portable/{data_model_id}returnsImportDataModelDTO.🤖 Generated with Claude Code