Skip to content

Resolve =replace= when it lands on an empty target - #322

Closed
julien-gadonneix wants to merge 2 commits into
facebookresearch:mainfrom
julien-gadonneix:fix-replace-op-on-empty-target
Closed

julien-gadonneix wants to merge 2 commits into
facebookresearch:mainfrom
julien-gadonneix:fix-replace-op-on-empty-target

Conversation

@julien-gadonneix

Copy link
Copy Markdown

ConfDict.ops.REPLACE is only consumed when the target subtree is truthy:

if self and kwargs.pop(ConfDict.ops.REPLACE, False):

So replacing a subtree that is missing, null or empty leaves the marker in the config as data, which later surfaces as =replace=: Extra inputs are not permitted when the config reaches a pydantic model.

ConfDict({"a": {"x": 1}}).update({"a": {"=replace=": True, "y": 2}})  # {'a': {'y': 2}}
ConfDict({}).update({"a": {"=replace=": True, "y": 2}})               # {'a': {'=replace=': True, 'y': 2}}

This regressed in #310; before it, the marker was always popped. It also sits oddly with #311 ("an empty mapping is a value like any other") — an empty target is a value, so replacing it should resolve.

Dropping the self and guard alone breaks carrying a pending =replace= inside a grid value, so instead ops are resolved when a patch is applied (update) and left pending when one is merely materialized (__init__, from_yaml, list items). to_uid still rejects unresolved ops.

pytest exca/test_confdict.py passes, plus two new tests.

Made with Cursor

ConfDict.ops.REPLACE was only consumed when the target subtree was
truthy, so replacing a missing, null or empty subtree left the marker
in the config as data, later tripping model validation ("=replace=:
Extra inputs are not permitted").

Ops are now resolved when a patch is applied (update) and left pending
when one is merely materialized (__init__, from_yaml, list items),
which is what carrying a =replace= inside a grid value relies on.

Co-authored-by: Cursor <cursoragent@cursor.com>
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 10, 2026
Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant