Repository navigation
Description
From Claude:
Why
The portability rules live in mdr_portability, but only export and import call them. Schema generation and the editing endpoints each check things their own way, or not at all. So a model can be saved in a state that export refuses and schema generation breaks on, and nobody learns about it until they try to download it.
#1462 is a concrete case. A cycle of embedded associations crashed OpenAPI schema generation. #1463 is the stopgap: find_children and find_ancestors in schema_generation_service.py now track the path they walk and return a 400 on a cycle. The same rule already existed in model_rules._check_for_containment_cycles (§5.4), which export runs through check_model_file. The rule now exists twice: once keyed by name over a ModelFile, once keyed by ID over DB rows and raised as HTTPException.
Grounding in code
- Export and import call the rules.
model_converter,mapping_group_converterandcrosswalk_converterruncheck_model_file,check_mapping_group_fileandcheck_crosswalk_file, so export never writes a file that import would refuse. - Schema generation does not call them. Beyond the Issue #1462: fix: refuse an embedded-association cycle instead of crashing schema generation #1463 cycle guard,
schema_generation_service.pyhas its own refusals ("multiple ancestor lines", "entity is referenced by an association but is not in the data model's entity set"). Some of these overlap with portability rules and some may not. Nobody has compared them. - Editing does not call them.
create_entity_associationchecks only for a duplicate parent/child pair, so the UI can save an embedded cycle.create_transformation/update_transformationcheck that IDs exist, not the mapping-group rules. - UI shows refusals only after export or import fails (
RefusalList,PortableFailureDialog). It never shows them while someone edits. - Existing data already has blockers.
scripts/measure_export_blockers.py(Issue #1393: feat: read-only count of what keeps each model and mapping group from exporting #1442) counts what export refuses today in each schema.
Direction (per discussion with Benito on #1463)
One set of portability rules, checked in one place:
- Schema generation checks the model against the portability rules before it walks the model, and refuses with the same
{code, element, reason}shape that export uses. The ad-hoc guards inschema_generation_service.pyare then removed, including Issue #1462: fix: refuse an embedded-association cycle instead of crashing schema generation #1463's guard once this replaces it. - The model, mapping-group and crosswalk editing endpoints run the same check on the result of the edit, so the UI can warn or block before the model goes non-portable.
- The UI shows those refusals inline (reusing
RefusalList) and does not keep its own copy of the rules.
Open questions
- Block or warn on edit? Existing models already fail rules (Issue #1393: feat: read-only count of what keeps each model and mapping group from exporting #1442's counts), so blocking every edit to one of them would lock users out. One option: block only edits that add a new violation, and warn about the ones already there.
- Checking a whole model on every edit means building its
ModelFileeach time. Is that fast enough, or do some rules need an incremental check? - Which of schema generation's own refusals are portability rules, and which (for example, Extension inclusions) belong only to generation?
Done means
- Schema generation and every editing endpoint refuse through
mdr_portability. - No portability rule is implemented a second time outside that component.
- A test shows an embedded cycle refused at edit time with the same code that export uses.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsBacklog
Activity
Issue #1472: feat: read and set an association's Name and Array throu…
bjagg commentedon Nov 12, 2026
Another case for this issue: the MDR's create path accepts two mappings with the same target in one group. The rule that a mapping is identified by its group and target path (§6.2) is checked only in
mdr_portability/mapping_group_rules.py. SoPOST /transformation_groups/creates the group, and export later refuses it withMAPPING_TARGET_SHARED.cbeach47 commentedon Nov 13, 2026
From Claude:
Refinement: the plan, split into PRs
This issue is done as a series of PRs. Each one leaves
mainconsistent, saysRefs #1468(notCloses), and ticks its row below. Whoever picks up next starts at the first unticked row.Decided
flush, run it again, and refuse with{code, element, reason}(422) if the edit adds any refusal. A model that already breaks rules can still be repaired, because edits that only remove refusals pass. Once no model breaks a rule, this is the same as "the model after every edit is portable".handleCreateEntity,ModelExplorer.tsx:381-390). Between them the entity sits at the top level, so a nestedIdentifierwould breakTOP_LEVEL_NAME_TAKEN. Entity create takes its parent in the same request, as attribute create already does (MDR: create-attribute is non-atomic — a dropped response orphans the attribute (persisted but unassociated) #1028).export_model/export_mapping_group/export_crosswalk, the converters' own refusals, so nothing restates the rules. On the seed,export_modeltakes 0.3–0.4 s on the largest models (4 and 10), against 3.4–10.9 s for schema generation. Checking an edit exports the model twice, before and after, so about 0.8 s on the largest seed model. That's fast enough to check the whole model, without a narrower check of only the part that changed.The PRs
generate_openapi_schemaruns the model check before walking it and refuses with any code exceptNOT_MIGRATED(which includes overlays) andMODEL_IDENTITY_INCOMPLETE(seed model 26, and modelsPOST /datamodels/saves with no organization). One app-level handler turnsPortabilityErrorGroupinto the 422 that/portablereturns. The schema download's toast lists the refusals (describePortableFailure+RefusalList)ASSOCIATION_CYCLE;test_schema_snapshots.pyis unchanged; #1463's tests still passcheck_name_and_array's blank-Namerefusal (#1508), which the guard now makes asFIELD_INVALIDASSOCIATION_CYCLE; two children under one parent with the sameNamerefused withASSOCIATION_NAME_TAKENNamerefused; deleting the last association refused withUNASSOCIATED_ATTRIBUTEcreate_entitytakes an optional parent;handleCreateEntitymakes one callArrayon a contained entity refused;DataTypeentity refused asNOT_MIGRATEDNOT_MIGRATEDor an overlay, so it's refusedValueName; blankContributorOrganization; a constraint on a portable modelexport_mapping_group. Check whetherMappingsView.tsx's own duplicate source→target check (:1149) can rely on the refusal insteadMAPPING_TARGET_SHARED;PATH_INVALIDexport_crosswalkCROSSWALK_SOURCE_DUPLICATEmapping_group_converter._export_path), so deleting a mapped attribute breaks the group withPATH_INVALID. Value-set edits can break crosswalks the same wayRefusalListNOT_MIGRATEDandMODEL_IDENTITY_INCOMPLETEtoo; delete #1463's guards (find_children,find_ancestors) and_entity_name's refusaltest_schema_generation_cycle.pyexpectsASSOCIATION_CYCLE"Tests" means automated tests in the PR (pytest for the backend, Vitest for the frontend). PRs that change the UI also list manual steps under "How to test".
Why the cycle guard is deleted last, not first.
export_modelrefusesNOT_MIGRATEDbefore it runscheck_model_file(model_converter.py:96-114), so for a model that isn't migrated the portability cycle rule never runs. Deleting #1463's guard now would bring back #1462's crash for any such model with an embedded cycle. On the raw seed, 17 of 21 models are refused as overlays orNOT_MIGRATEDbefore the rules run; dev'spublicnow exports every model (#1393), and demo isn't converted yet. #1513 converts both. PR 1 makes the portability rule refuse cycles on every model it can check, and PR 11 deletes the guard once that's all of them.Reusing
_find_containment_cycleson database rows to delete the guard sooner isn't worth it. The generator would still build its own graph from rows, so "which associations contain" would still be written twice. And #1486 deletes that code anyway.Related, outside this issue
Other paths that write model content without the rules:
/clone/(import_export_service.clone_datamodel) writes rows itself, though spec §8 says clone is export then import. It should go through the converter or be removed.import_export_endpoints.py:33, MDR portability: serve the portable converter from the export and import endpoints #1408).Each PR also updates the
mdr_servicesREADME and the spec's list of the converter's callers (§8) where it adds one.Issue #1468: PR revisions
Issue #1468: feat: refuse a non-portable model in schema generation (#…
Issue #1513: refactor: list crosswalk pairs with the converter's live…
Issue #1513: test: stop two tests leaning on NOT_MIGRATED's pass, and…
cbeach47 commentedon Nov 19, 2026
From Claude:
From #1521:
clone_datamodelsets noContributorOrganization(CreateCloneDTOhas none), so a clone's portable identity is incomplete. Once this issue removesMODEL_IDENTITY_INCOMPLETEfromCODES_NOT_YET_REFUSED, schema generation refuses every clone.test_clone_datamodel_sqlworks around it by copying the source's organization onto the clone.Before the pass goes, this needs a decision on which organization a clone gets (the source's, the caller's tenant, or a required field on
CreateCloneDTO), and then the change inclone_datamodel.Issue #1513: feat: give the seed dev's models 3, 6, 14 and 17, and re…
cbeach47 commentedon Nov 20, 2026
I need to pause this effort for now.
Handoff notes for whomever picks it up next:
1468-handoff.md