fix(mapping): read Manual Mapping save fields from panel state, send excluded/attribute mappings - #150
Conversation
…excluded/attribute mappings When saving an entity mapping from Manual Mapping, id_column/label_column were read from the panel's visual summary text (which could be stale or show "Not set"), instead of from the panel's own internal state (EntityPanelState). attribute_mappings and, when present, excluded_attributes are now sent too — previously neither was persisted from this screen at all. When saving a relationship mapping, sourceColumn/targetColumn are now likewise read from RelPanelState instead of the visual summary, and source_class/target_class/direction are now sent (recovered from the existing mapping when there is one) along with attribute_mappings/ excluded_attributes. Previously a relationship created via Manual Mapping carried no source/target entity or direction, which is exactly what the consistency-check backfill (domain/range resolution) has to reconstruct after the fact — see the companion generation PR.
|
|
benoitcayladbx
left a comment
There was a problem hiding this comment.
Relevant — please keep this. Manual Mapping on current develop still reads ID/label/source/target from the summary DOM (epSummaryId, rpSummarySource, …) and still posts class_name / property_name. Those keys are ignored by Mapping.build_entity_mapping / build_relationship_mapping, which expect ontology_class_label / property_label. So this PR fixes a real save-corruption + schema-drift bug, not a 0.7.1 leftover.
Please address the items below before we merge. Merge after or with #152 (backend preserve/backfill); landing 150 alone still drops excluded_attributes on any save that omits the key.
Must fix
-
Remove
//JERRYcomments (.cursor/05 §English-only artifacts,src/.coding_rules.md§3). Author tags and commented-out old lines (//JERRY const idColumn = …) do not belong indevelop. Delete the old lines; keep theEntityPanelState/RelPanelStatereads. -
Always send
excluded_attributes, including[]. You only attach the key whenlength > 0. Combined with #152’s “omit ⇒ preserve previous list”, a user who clears every exclusion in Manual Mapping cannot persist that clear — the old list comes back. Preferred contract:- frontend always posts
excluded_attributes: [...EntityPanelState.excludedAttributes](possibly empty); - backend treats key present (even empty) as authoritative, and only carries forward when the key is absent. See the #152 comment.
- frontend always posts
-
First-time relationship save still stores empty
source_class/target_class. Copying fromexistingRelis a no-op when there is no previous mapping. Either:- resolve domain/range from the loaded ontology in this save path, or
- let
Mapping.build_relationship_mappingfill them when the payload omits them (better: one place, used by Manual + any other client).
#152’s diagnostic fallback is display-only; it does not persist the fields.
-
Changelog —
changelogs/v0.8.0/<github-user>_YYYY-MM-DD.log(English,.cursorrules). -
CLA still pending.
Nice to have (same PR is fine)
- Duplication: the
filteredAttrMappingsblock is copied for entity and relationship. Extract a small helper (Fowler Extract Function,src/.coding_rules.md§9). - Tests: there are no JS unit tests for this file; at least extend
tests/units/mapping/so a payload withontology_class_label+excluded_attributesround-trips throughadd_or_update_entity_mapping(covers the field-name fix even without a browser).
The state-vs-summary change itself is the right fix — just clean the debug comments and make the excluded/source-class contract explicit.
What
Two related bugs in saving from Manual Mapping (the SQL-first alternative to the Designer for creating mappings directly):
id_column/label_columnwere read from the panel's visual summary text (which can be stale, or show "Not set" even when the panel's actual state is valid), instead of from the panel's own internal state (EntityPanelState). The save call now also sendsattribute_mappingsand, when present,excluded_attributes— neither was persisted from this screen before at all.sourceColumn/targetColumnare likewise now read fromRelPanelStateinstead of the visual summary. The save call now also sendssource_class,target_classanddirection(recovered from the existing mapping when there is one), plusattribute_mappings/excluded_attributes.Why
Reading from the rendered summary text meant a save could silently capture the wrong (or empty) ID/label/source/target column whenever the summary hadn't caught up with the panel's real state. Not sending
attribute_mappings/excluded_attributesmeant those were lost entirely when saving from this screen. Not sendingsource_class/target_class/directionfor relationships meant every relationship created via Manual Mapping needed a separate backfill step to reconstruct that information from the ontology after the fact.How to test
source_class/target_class/directionare present on the saved relationship without needing any separate consistency-check pass.Note for maintainers
There's a companion fix we're holding back for now:
src/back/objects/mapping/Mapping.pyin our 0.7.1-based tree also (a) preserves an existingexcluded_attributeslist on update when the incoming payload omits it, and (b) backfillssource_class/target_classfrom the property's domain/range when a relationship consistency-check finds them empty (the legacy-data counterpart to this PR's frontend fix). We sawMapping.pyhas since grown a substantial schema-drift feature ondevelop, so we want to make sure our change still makes sense against that before proposing it — will follow up with a separate PR once we've checked.