Skip to content

--definitions-file can delete a semantic model or metric - #424

Merged
marcociav-exmergo merged 1 commit into
mainfrom
issue-254
Sep 5, 2026
Merged

--definitions-file can delete a semantic model or metric#424
marcociav-exmergo merged 1 commit into
mainfrom
issue-254

Conversation

@spascarella

Copy link
Copy Markdown
Collaborator

Problem

--definitions-file can create and evolve a semantic model or metric, but not remove one. Deleting means sending the whole file back without the definition, which is the cost the per-definition unit exists to remove.

The design question was what a dangling metric reference should do at plan time. The whole-plan delete guard reasons about deleted files and ref(); a definition removal deletes no file, and the name it takes away lives in a file that survives, so that guard cannot see it.

What changes

A definitions entry can carry "op": "delete", naming the definition and no content:

{"definitions": [{"kind": "metric", "name": "doubled", "op": "delete"}]}
Removal is always declared. Nothing is removed for going unmentioned, and one payload names each definition once, so the result cannot depend on read order.
semantic define refuses a removal; update and plan accept one, reported as a fourth class, removed.
A removal the surviving project still reads is refused, naming the reader and its file. Adding that reader's own delete or update to the same payload satisfies it.
A removal that would empty a file of semantic content is refused, pointing at transform plan --edits-file: deleting a file is a file-level act.
Comments and every other byte survive. A block's key: line goes only with its last item. DexEngine takes the same payload through definitions=.

Fix

Refuse rather than warn, because dbt would refuse anyway: a dangling metric input fails dbt parse, the gate every semantic plan already passes, so warning would only matter where that gate is off (--no-parse, no dbt) and would store a plan dex knows cannot be applied. maintain semantic stays the tool for drift that arrived on its own, not for a break this command is authoring.

check_removals repeats the delete guard's shape one namespace over: the project the payload leaves behind is built in memory and every surviving metric re-resolved against it, so the check reads the end state rather than the sequence. A removed semantic model takes its measures (create_metric included); a name re-declared elsewhere in the payload orphans nothing. Filter-string Metric() calls stay dbt's parser's to catch.

Known gap for its own issue: deleting a whole semantic YAML through transform plan still bypasses this guard, since validate_deletions reasons about ref().

Related issue

Closes #254

@spascarella spascarella self-assigned this Sep 3, 2026
@marcociav-exmergo
marcociav-exmergo merged commit 7045595 into main Sep 5, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove a single definition through --definitions-file

2 participants