Skip to content

Fix Patch.update shared mapping ownership - #4144

Open
peterolkhov wants to merge 1 commit into
plotly:devfrom
peterolkhov:codex/fix-patch-update-source-mapping
Open

peterolkhov wants to merge 1 commit into
plotly:devfrom
peterolkhov:codex/fix-patch-update-source-mapping

Conversation

@peterolkhov

Copy link
Copy Markdown

Fixes #4143

Reusing one dictionary for two Patch.update calls with different keywords currently changes the first queued merge when the second call runs. In a running Store callback, January and February both receive200 instead of100/200, and the input dictionary is changed too.

Copy the top-level dictionary before merging keywords. Nested values stay shallow and keywords keep precedence. The fix is one production line, with unit controls and a permanent dash_duo regression checking the actual Store output.

Native validation:

  • Original public reproduction:2 failing assertions,4 passing controls. Candidate:6 passes; both permanent regressions fail before and pass after.
  • Specific patch unit/integration files:38 passes.
  • Official builds and Python3.10/3.14 unit commands pass. Each unit job reports746 Python passes/7 skips,124 renderer passes and79 generator passes. Official Python3.10 lint passes.
  • Required different-model review completed with Terra high after Sol high authored the change.

Codex generated the implementation, tests and description. Tests ran on the exact source commit in standard GitHub-hosted runners; no local or human review is claimed. The full integration suite was not run, per the project's instruction to use specific files. Unit skips are recorded in the linked logs.

@sonarqubecloud

Copy link
Copy Markdown

@camdecoster

Copy link
Copy Markdown
Contributor

Thanks for the PR! Our team will take a look and follow up.

@T4rk1n T4rk1n left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix is right: copying E before merging stops the bug from the issue, and it also stops a later edit to the caller's dict from changing a merge that's already queued. Nothing blocks merge. The notes below are test cleanups.

data = json.loads(raw_data)
return all("amount" in data.get(month, {}) for month in ("jan", "feb"))

until(data_received, timeout=3)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The data_received poll plus the second Pre is more than this needs. JSON.stringify output is deterministic here, so dash_duo.wait_for_text_to_equal("#records-json", '{"jan":{"retained":1,"currency":"USD","amount":100},"feb":{"retained":2,"currency":"USD","amount":200}}') covers it in one line. Can you switch to that and drop the helper?


@app.callback(
Output("records", "data"),
Output("common-json", "children"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The common-json output only checks that the input dict wasn't changed, and test_pat022 already covers that without a browser. Can you drop it so this test only checks the Store result?

Comment thread tests/unit/test_patch.py
]


def test_pat025_patch_update_union():

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_pat024 and test_pat025 pass on dev too, so they don't cover the fix. The other case the copy fixes is changing the dict after the call: p.update(common), then common["x"] = 1, used to change the queued merge. Can you add that check here (or replace test_pat025 with it)?

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.

[BUG] Patch.update mutates a shared mapping and rewrites earlier merges

3 participants