Skip to content

Fix ctx.triggered and args_grouping for pattern-matching ids with non-ASCII characters - #4241

Open
farisbasha wants to merge 2 commits into
plotly:devfrom
farisbasha:fix-non-ascii-stringify-id
Open

farisbasha wants to merge 2 commits into
plotly:devfrom
farisbasha:fix-non-ascii-stringify-id

Conversation

@farisbasha

@farisbasha farisbasha commented Dec 4, 2026 •

Copy link
Copy Markdown

stringify_id escapes non-ASCII characters (json.dumps default), but the renderer's stringifyId uses JSON.stringify, which keeps them as they are. The renderer builds changedPropIds with its version, and the backend looks those strings up in keys made by stringify_id, so they never match when a dict id value (or key) has a non-ASCII character.

Repro (posting what the renderer sends for a click on the first button):

app.layout = html.Div([html.Button(id={"type": "b", "index": i}) for i in ["café", "abc"]] + [html.Div(id="out")])

@app.callback(Output("out", "children"), Input({"type": "b", "index": ALL}, "n_clicks"))
def f(_):
    print(ctx.triggered)       # [{'prop_id': '{"index":"café","type":"b"}.n_clicks', 'value': None}]
    print([(g["str_id"], g["triggered"]) for g in ctx.args_grouping])
    # [('{"index":"caf\\u00e9","type":"b"}', False), ('{"index":"abc","type":"b"}', False)]
    return "x"

ctx.triggered[0]["value"] is None instead of the clicked button's n_clicks, no entry in ctx.args_grouping is marked as triggered, and ctx.inputs is keyed by the escaped form. With ASCII ids all of this works.

Fix: stringify_id passes ensure_ascii=False for the key and value, so it gives the same string as the renderer. Other escapes (quotes, control characters) are the same in both.

Contributor Checklist

  • This PR targets dev (fix or chore) or next (feature, new API, breaking change), see Which branch to target
  • I have broken down my PR scope into the following TODO tasks
    • make stringify_id match the renderer's stringifyId for non-ASCII characters
    • unit tests for stringify_id and for ctx.triggered / ctx.args_grouping through /_dash-update-component
  • I have run the tests locally and they passed. (refer to testing section in contributing)
  • I have added tests, or extended existing tests, to cover any new features or bugs fixed in this PR

optionals

  • I have added entry in the CHANGELOG.md
  • If this PR needs a follow-up in dash docs, community thread, I have mentioned the relevant URLS as follows
    • this GitHub #PR number updates the dash docs
    • here is the show and tell thread in Plotly Dash community

Tests run

On a Linux server (Python 3.12): the two new tests fail on dev and pass with the change. pytest tests/unit: 771 passed, 7 skipped, 5 failed; the same 5 fail without the change in this setup (generated component files copied from the 4.5.2 wheel: 4 test_dash_table_typing cases, and test_process_server_smoke, which needs tests/assets, not checked out). black 22.3.0 and flake8 are clean on the changed files, pylint on dash/_utils.py. Integration (Selenium) tests were not run.

This PR was prepared with AI assistance (Claude).

The renderer's stringifyId uses JSON.stringify, which leaves non-ASCII
characters as they are, while stringify_id escaped them as \uXXXX. The
changedPropIds sent by the renderer are looked up in strings made by
stringify_id, so with a pattern-matching id such as {"index": "café"}
ctx.triggered gave value None and args_grouping marked nothing as
triggered.
@sonarqubecloud

sonarqubecloud Bot commented Dec 4, 2026

Copy link
Copy Markdown

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.

1 participant