--definitions-file can delete a semantic model or metric - #424
Merged
Conversation
marcociav-exmergo
approved these changes
Sep 5, 2026
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.
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