Repository navigation
Issue #1472: feat: read and set an association's Name and Array through the MDR API - #1508
Merged
Merged
Conversation
…gh the MDR API The entity and attribute association DTOs carry Name and Array. Create stores a sent value, or the rule's when it's not sent or null. Update keeps a sent value through Relationship/Placement/child edits in the same request, and a sent null resets it to the rule's. A blank Name is refused, and so is setting either one across data models or on an association with ExtendedByDataModelId. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6 tasks done
8 of 9 tasks
bjagg
approved these changes
Nov 12, 2026
bjagg
left a comment
Contributor
There was a problem hiding this comment.
Thanks, Dereck. I checked it at 9d18e89.
- Write paths:
- Create uses a sent
Name/Arrayand otherwise the rule's value. - Update recomputes only the fields the request didn't send, so a sent value survives a
Relationship/Placement/child change in the same request. That's the fix, and the test covers it. - The guards look only at sent fields, and use the association's ids after the edit.
- Create uses a sent
- CI: ran all 13 tests in
test_association_name_writes.pyagainst Postgres. - Guards on dev after #1388: read-only, every association in
publicandtenant_lif_team. Neither has a live association withExtendedByDataModelId, and neither has a cross-model entity association, so the guards block nothing there today. - Wording nit: the body says a sent
null"stores NULL". In the code, the same request recomputes it, becausedto.Name is None. So what's stored is the rule's value, which is what the reset test asserts. The behaviour is right; only the description differs. - For later, not this PR: renaming an association renames the child's key in the schema. Existing mappings whose JSONata writes the old key then no longer match the schema, and nothing warns. It could go in #1472's notes or the UI help text.
Approving.
…le's value The update comments said a sent null is stored as NULL. The same request recomputes it, so the rule's value is stored (review on #1508). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
@bjagg, thanks for the review. I merged main (#1510) into this, and CI is green at |
bjagg
added a commit
that referenced
this pull request
Nov 12, 2026
…anch Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bjagg
added a commit
that referenced
this pull request
Nov 12, 2026
…#1509) ##### Description of Change **Problem.** PR #1508 (the API half of #1472) lets the MDR API read and set an association's `Name` and `Array`, but the MDR UI can't edit them yet. **Solution.** This is the UI half of #1472. It's stacked on #1508, so the diff shrinks to this PR's commit once that merges. - **Edit Association** (entity and attribute associations) shows **Name** and **List under this parent**. - Only changed fields are sent, as before. - Clearing Name sends `null`, which the API resets to the default key. - A whitespace-only Name is sent as typed, so the API's 400 explains why it was refused in the dialog's error line. Cross-model and `ExtendedByDataModelId` refusals show the same way. - **The dialog title** shows the association's `Name`, the key the child appears under. Before this PR, `handleEditAssoc` overwrote `itemToEdit.Name` with the tree label "for display". With `Name` now a field, that override would make every save send a `Name`. - **+ Existing Entity / Attribute** (create), in a model's own dialog: picking the child starts the switch at the child's own `Array`, or off for a Reference (#1471), so the user sees the list setting and can change it. This follows the decision on #1429/#1472: after #1498, an imported list element is stored as single, so the old default (the rule) is wrong for imported models. - `SelectDialog` gets an optional `onSelected` hook for this. Value sets don't pass it, so they're unchanged. - The create template only copies truthy values it already has, so the switch's value is carried over explicitly (`withCreateArray`). Otherwise an unticked switch would be dropped. - **Overlay models' create dialogs** don't show the switch. Their associations are cross-model or `ExtendedByDataModelId`, which the API refuses to give an `Array`, so sending one would break every plain create there. **Limitations.** - Changing Placement to Reference after picking the child doesn't reset the switch. What's sent is what the switch shows. - `Name` is edit-only, as decided. - An element `Array` edit can still overwrite a value set here (#1478), and a clone recomputes `Name` (#1500). - Pre-existing: every edit-dialog save also sends `ActivationDate`, because of the dialog's minute-precision round trip. That's unchanged here. **Overlap with #1507** (cbeach47, the frontend half of #1429): #1507 makes the UI's own schema and sample records read the association's `Array`, and this PR is where a user sets it. The two share no files (#1507 changes `modelService.ts` and `types.ts`), so either can merge first. Once both are in, a switch flipped here should show up in #1507's schema and samples after the dialog's refetch. ##### Related Issues Closes #1472 (with #1508) Refs #1429, #1471, #1478, #1500, #913 ##### Type of Change - [x] New feature (non-breaking change which adds functionality) ##### Project Area(s) Affected - [x] frontends/ - [x] test/ or e2e/ --- ##### Checklist - [x] commit message follows commit guidelines (see commitlint.config.mjs) - [x] tests are included (unit and/or integration tests) - [x] pre-commit hooks have been run successfully (on the changed files: cspell passed. `ty-check` and `pytest` were skipped, since this diff is frontend-only and the Python tree is #1508's, which ran the full suite) ##### Testing - vitest: 62 passed (8 new, in `associationKeyFields.test.ts`). `npm run build` (tsc -b + vite) passes; eslint reports 0 errors. - **Browser, against the real MDR API** (this branch's code, seeded Postgres), on model 26 (R1 Demo Source Data Model). I checked each step's request body, and read the stored rows once, after the last step: - edit `person → employment`: Name `jobs`, list on → `PUT {"Name":"jobs","Array":true}` (200; reopening shows `jobs`, on); - clear Name → `PUT {"Name":null}`, final row `(employment, t)`; - Name `" "` → 400, and the dialog stays open with "Name can't be blank: …"; - attribute association `preferences.preferred_org_types`, list off → `PUT {"Array":false}`, final row `f`; - + Existing Attribute `preferred_org_types` (a list) on `person`: the switch starts on → `POST … "Array":true`, final row `t`; - + Existing Attribute `id` (single) on `employment`: starts off, ticked → `POST … "Array":true`, final row `t`; - + Existing Entity `preferences` (single) under `person`, untouched → `POST … "Array":false`, final row `f`; - model 17 (overlay): the + Existing Attribute dialog has no list switch. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: dereck <dereck.haskins@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Benito J. Gonzalez <bgonzalez@unicon.net>
This was referenced Nov 13, 2026
bjagg
pushed a commit
that referenced
this pull request
Nov 18, 2026
…1523) _From Claude:_ ##### Description of Change **Problem.** Schema generation applies its own checks, not the portability rules. So it builds a schema for a model that export refuses, such as one with a containment cycle or with two children under one association `Name` (possible since #1508). In the second case it keeps only one of the two children, with no error. **Solution.** PR 1 of #1468's plan ([refinement](#1468 (comment))). - **Generator:** `generate_openapi_schema` calls the new `refuse_non_portable_model` first. It exports the model through `portability_converter.export_model` and raises export's refusals. - **Endpoint:** a new app-level handler in `core.py` turns those refusals into a 422 with every `{code, element, reason}`, the same response `/portable` gives. - **Frontend:** a refused schema download opens a dialog listing each reason (`RefusalList`). Any other error is still a toast. - **Overlay conversion:** `generate_matrix` records a refused combination as that same 422, so `convert_overlays` still reports every reason in `ConversionFailed`. The schema snapshots record it the same way. - **Shared:** `list_refusals` in `mdr_portability` builds the `{code, element, reason}` list for the endpoint, the conversion and the tests. **Let through for now.** A model refused only with these codes is generated as before (`CODES_NOT_YET_REFUSED`): - `NOT_MIGRATED`, which includes overlays, until #1513 clears them from dev and demo. Export refuses it before checking the rules, so #1463's cycle guard still protects these models. - `MODEL_IDENTITY_INCOMPLETE`, which doesn't change the schema. `POST /datamodels/` still saves a model with no organization, until #1468 PR 6 refuses it. PR 11 of #1468 removes both, along with #1463's guard. **Side effects.** - A model export refuses for any other reason now gets a 422 instead of a schema. No seed model is refused with any other code, so the snapshot suite is unchanged. On dev, every model in `public` exports (#1393). - Each generation runs one export: 0.3–0.4 s more on the largest seed models. - `mdr_services` is packaged only by `lif_mdr_api`. Its workflow's `paths:` cover the changed bricks, and `check_workflow_paths.py` passes. **How to test.** Locally: 1. The stack starts. GraphQL, the translator and semantic search load model 17. 2. Schema downloads work for models 4, 17 and 26, bare and full. 3. On a model that exports, set a Reference that points back up the tree to Embedded (Edit Association → Placement). The download opens the dialog with `ASSOCIATION_CYCLE`. Undo the change afterwards. 4. Do the same on model 29, which isn't migrated (Profile's `RefProfile`). #1463's toast appears, as before. 5. A 26 → 17 translation still runs. 6. With the cycle from step 3 in place, exporting the model as a portable file lists `ASSOCIATION_CYCLE` (the refusal response is now built by `list_refusals`). 7. Importing a portable file for a model that's already installed is refused with `MODEL_EXISTS` ("already installed"), not as a 422. Before promoting to demo, run `measure_export_blockers.py` there. A model refused with any code other than the two above would start returning 422 to the services that load it. ##### Related Issues Refs #1468 Refs #1513, #1463 ##### Type of Change - [x] New feature (non-breaking change which adds functionality) ##### Project Area(s) Affected - [x] bases/ - [x] components/ - [x] frontends/ - [x] test/ or e2e/ - [x] API endpoints - [x] Documentation (docs/, READMEs, ARCHITECTURE.md, CLAUDE.md) --- ##### Checklist - [x] commit message follows commit guidelines (see commitlint.config.mjs) - [x] tests are included (unit and/or integration tests) - [x] documentation is changed or added (in /docs directory) - [x] code passes linting checks (`uv run ruff check`) - [x] code passes formatting checks (`uv run ruff format`) - [x] code passes type checking (`uv run ty check`) - [x] pre-commit hooks have been run successfully ##### Testing - [x] Manual testing performed - [x] Automated tests added/updated - **New:** `test_schema_generation_portability.py`, 7 tests. Two compare the whole refusal for a cycle and for a duplicate `Name`. One checks the endpoint's 422 body, with and without `download=true`. Two check that a model that exports, and one refused only for its identity, still generate. One checks that `generate_matrix` records the refusal as the endpoint's 422; it fails without that change. To confirm the tests cover the check, I removed the `refuse_non_portable_model` call: the 5 tests that expect a refusal fail, and the 2 that expect a schema pass. - **Fixtures:** the enum-order test now sets a `ValueName` on the values it adds. The mocked-session unit tests stub the check. - **Results:** with `main` merged in, the `mdr_restapi`, `mdr_services`, `mdr_portability`, `translator` and `scripts` suites: 988 passed, 1 skipped, 1 failed. The failure is the Open Badges v3 case of `test_a_clone_generates_the_same_schema_as_its_source`, which fails the same way on a clean `main` checkout locally. Frontend: `tsc -b`, Vitest (66) and eslint pass, with no new warnings. ##### Additional Notes The Open Badges v3 clone case passed in Benito's run of this branch, but fails here on both this branch and `main`. No issue tracks it yet. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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
Problem. Since #1386, an association's
NameandArrayset the child's key and cardinality under that parent, and since #1429 (#1498) the generated schema reads the association'sArray. But nothing could read or set them through the API: none of the six association DTOs had them.Solution. This is the API half of #1472. The UI half is a second PR.
Read:
GETand every other response from/entity_associations/and/entity_attribute_associations/now includeNameandArray. The change is additive.Create:
Name/Arrayare optional. Not sent, ornull: the rule's value, as today (association_name.py). Sent: stored as given.Update: a sent value is kept. Before this PR, a request that changed
Relationship/Placement/the child and sent a value equal to the old rule's would have had that value recomputed. Now only fields the request didn't send are recomputed. A sentnullis recomputed in the same request, so what's stored is the rule's value, and the UI can offer a reset.Refused with 400:
Name(""or whitespace), since it's the child's key in the schema;ExtendedByDataModelId, or that the same request gives one. Per MDR portability: edit an association's Name and Array through the API and UI #1472 this is a guard until model types go away.An edit that doesn't send
NameorArrayis unaffected on those rows, and does no extra lookups.Arraycan be set on a Reference association (MDR portability: decide whether a Reference association can be a list #1471). Nothing reads it for references yet, so it reaches only export and import.Limitations (named, not fixed here):
Arrayedit still copies onto any association whoseArrayequals the rule's value. So a value set here that happens to match the rule can be flipped by a later element edit.Name, so aNameset here doesn't survive a clone.Arraydoes survive (Issue #1429: feat: generate an element's cardinality from its association's Array (backend) #1498 copies it), and a test covers that.Array, not the association's (jinja_translation_service.py:908-911). MDR: remove the unused Jinja translation endpoint #1503 removes that endpoint.ASSOCIATION_NAME_TAKEN) is Check portability rules in one place: schema generation and MDR editing should call mdr_portability #1468.Side effects.
Name/Arrayaren't in it until the UI PR.GET /import_export/export/...endpoints gain the two fields on each association too, becauseSingleDataModelExportDTOembeds the read DTOs. The legacy import ignores them: itsImport*AssociationDTOs are separate, and pydantic drops extra fields.Shared bricks.
mdr_servicesis packaged bylif_mdr_apionly.mdr_dtois packaged bylif_mdr_apiandlif_learner_data_export_api(additive fields; nothing outside the MDR imports these DTOs). Both workflows'paths:cover the bricks.How to test. With a local MDR:
PUT /entity_associations/{id}with{"Name": "Studies", "Array": false}on an embedded list child, then generate the model's schema: the child appears asStudies,type: object.PUTagain with{"Relationship": "takes"}:NamestaysStudies.PUTwith{"Name": null}:Namegoes back to the rule's key.PUTwith{"Name": " "}, or{"Array": true}on a cross-model association: 400.Related Issues
Refs #1472 (the UI half follows in a second PR)
Refs #1429, #1478, #1500
Type of Change
Project Area(s) Affected
Checklist
uv run ruff check)uv run ruff format)uv run ty check)Testing
test/bases/lif/mdr_restapi/test_association_name_writes.py: 10 new Postgres-backed tests (create, update, the same-request fix, null reset, blankName, both guards, the generated schema, clone keepsArray). 9 failed before the change. The null-reset test passed before it only because the DTOs dropped the fields.ExtendedByDataModelId, the same-requestExtendedByDataModelId, blankName) or always recomputingName/Arraymakes at least one test fail.lif-pgtest, at87c956d): 1919 passed, 1 skipped. The skip is the snapshot regenerator (LIF_UPDATE_SCHEMA_SNAPSHOTS). On main before this PR: 1909 passed, 1 skipped.🤖 Generated with Claude Code