Fix DBT converter round-trip losses entity issue - #315
Conversation
|
@QMalcolm mind take a look? |
There was a problem hiding this comment.
🟡 Changes recommended
The code change also affects UNIQUE and FOREIGN entity classification, but the added regression test only covers PRIMARY, leaving key paths untested.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR fixes a round-trip conversion bug in the DBT converter where PRIMARY/UNIQUE/FOREIGN entities could be silently dropped during MSI → Ossie → MSI when the entity expr differs from the entity name.
Changes:
- Update
OssieToMSIConverterfield classification to recognize keys by eitherfield.nameor the field expression (expr). - Add a regression test to ensure a PRIMARY entity with
expr != namesurvives MSI → Ossie → MSI.
File summaries
| File | Description |
|---|---|
converters/dbt/src/ossie_dbt/ossie_to_msi.py |
Classifies PRIMARY/UNIQUE/FOREIGN entities by matching either field.name or expr against key sets. |
converters/dbt/tests/test_ossie_to_msi.py |
Adds a regression test covering the PRIMARY entity expr != name round-trip case. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| assert len(sm.entities) == 1 | ||
| assert sm.entities[0].name == "customer_id" | ||
| assert sm.entities[0].expr == "id" | ||
| assert sm.entities[0].type is EntityType.PRIMARY |
| semantic model measures, so there is no measure classification step. | ||
| """ | ||
| if field.name in primary_key_cols: | ||
| if field.name in primary_key_cols or expr in primary_key_cols: |
There was a problem hiding this comment.
I think that matching by expr membership (in addition to name) opens a false-positive collision risk: if an unrelated field's expr happens to equal another field's key expression, it gets misclassified.
For instance, if we have a dataset orders with primary_key=["id"] and two fields sharing expr="id" (something like customer_id and foo_id) both get classified as PRIMARY entities, and the dimension is lost.
On the other hand, a genuine FK field whose expr collides with another field's PK expr gets classified PRIMARY instead of FOREIGN, losing the relationship's cardinality on round-trip.
Since expr isn't guaranteed unique across fields the way name is, this trades one false-negative bug for a false-positive one 😄
Summary
Currently a primary, unique, and foreign entity whose expression differs from its name is silently lost on MSI → OSI → MSI conversion. This is due to the following:
From
converters/dbt/src/ossie_dbt/msi_to_osi.py, we have following:However, from
converters/dbt/src/ossie_dbt/osi_to_msi.pyfollowing:Here is the local test result with the fixed code and newly added test:
Related Issues
Checklist
Specification
core-spec/and follow the existing structureOntology
ontology/are consistent with spec changesConverters
converters/is updated to reflect spec or ontology changesValidation
validation/are updated if the spec changedDocumentation
docs/is updated to reflect any user-facing changesCONTRIBUTING.mdis updated if the contribution process changedExamples
examples/are added or updated for any new spec constructs or converter supportTests
pytest/ CI green)Compliance