fix(worker): align patchConfig with the API on key removal - #110
Merged
Conversation
The worker's patchConfig did a plain Object.assign into the processing config, so a plugin had no way to reset a config key and a null ended up stored as-is. The API's PATCH already treats null as a removal ($unset), and validates the resulting config against the plugin's config schema — so a null written by a run left the document invalid for the very endpoint that would save it next (400 on the next save from the UI). Align the two: extract the merge into applyConfigPatch, where a null value deletes the key, and unit test the semantics. Undefined deletes it too — plugins already use that idiom and the mongo client, built with ignoreUndefined, already dropped those keys on write; the in-memory config now matches what is stored.
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.
A plugin calling
patchConfig({ someKey: null })had its null stored as-is: the worker merged the patch withObject.assign, so a key could never be reset. The API'sPATCH /processings/:idalready treats a top-level null as a removal, and validates the resulting config against the plugin's config schema — so a null written by a run left the document invalid for the very endpoint that would save it next (400 on the next save from the UI).In
patchConfig(worker/src/task/task.ts), iterating over patch entries now deletes keys whose value isnullorundefinedfrom the in-memory config instead of assigning them.Why: the worker and the API were writing the same document under two different conventions; the worker should at least be aligned with the API.
Heads-up:
undefinednow deletes the key too. Several plugins already use that idiom ({ datasetMode: 'update', datasets: undefined }) and it already behaved that way in the database, since the mongo client is built withignoreUndefined: true; the in-memory config the run reads is now consistent with what gets stored. Existing documents that already hold a null in their config are not cleaned up by this change.