Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
- [#4218](https://github.com/plotly/dash/pull/4218) Fix `pages_folder` written with `/` on Windows, such as `"src/pages"`, giving wrong page module names and paths. Fixes [#4217](https://github.com/plotly/dash/issues/4217).
- [#4220](https://github.com/plotly/dash/pull/4220) Fix the `DASH_VALIDATE_CALLBACKS` environment variable being ignored, although `Dash.run` and `Dash.enable_dev_tools` document it for `dev_tools_validate_callbacks`. Fixes [#4219](https://github.com/plotly/dash/issues/4219).
- [#4235](https://github.com/plotly/dash/pull/4235) Fix FastAPI deep links for mounted Dash apps and disabled or repeated lifespans. Apps sharing a server respect their URL prefixes, and explicit routes take precedence even when added after startup. Fixes [#4234](https://github.com/plotly/dash/issues/4234).
- [#4241](https://github.com/plotly/dash/pull/4241) Fix `ctx.triggered` giving `None` as the value and `ctx.args_grouping` marking nothing as triggered when a pattern-matching id contains non-ASCII characters, such as `{"index": "café"}`. `stringify_id` now keeps those characters, like the renderer.

## [4.5.2] - 2026-11-27

Expand Down
9 changes: 7 additions & 2 deletions dash/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,14 @@ def split_callback_id(callback_id):


def stringify_id(id_) -> str:
# Must match stringifyId in the renderer, which uses JSON.stringify and so
# keeps non-ASCII characters as they are: the changedPropIds it sends are
# compared with these strings.
def _json(k, v):
vstr = v.to_json() if hasattr(v, "to_json") else json.dumps(v)
return f"{json.dumps(k)}:{vstr}"
vstr = (
v.to_json() if hasattr(v, "to_json") else json.dumps(v, ensure_ascii=False)
)
return f"{json.dumps(k, ensure_ascii=False)}:{vstr}"

if isinstance(id_, dict):
return "{" + ",".join(_json(k, id_[k]) for k in sorted(id_)) + "}"
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/library/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,15 @@ def test_ddut001_attribute_dict():
)
def test_ddut002_pascal_case(value, expected):
assert utils.pascal_case(value) == expected


def test_ddut003_stringify_id_keeps_non_ascii():
# Same output as the renderer's stringifyId (JSON.stringify), which does
# not escape non-ASCII characters.
assert (
utils.stringify_id({"type": "b", "index": "caf\u00e9", "n\u00e4me": 1})
== '{"index":"caf\u00e9","n\u00e4me":1,"type":"b"}'
)
assert utils.stringify_id({"type": "b", "index": 'a"\n'}) == (
'{"index":"a\\"\\n","type":"b"}'
)
44 changes: 44 additions & 0 deletions tests/unit/test_callback_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,47 @@ def test_create_callback_id_dict_id_without_dots_unaffected():
id_part, prop_part = callback_id.rsplit(".", 1)
assert prop_part == "value"
assert json.loads(id_part) == {"type": "widget", "index": 2}


def test_callback_context_with_non_ascii_pattern_matching_id():
"""The renderer builds changedPropIds with JSON.stringify, which keeps
non-ASCII characters, so the triggered input must still be found when a
pattern-matching id value contains one."""
app = dash.Dash(__name__)
app.layout = dash.html.Div()
seen = {}

@app.callback(
Output({"type": "out", "index": "caf\u00e9"}, "children"),
Input({"type": "btn", "index": dash.ALL}, "n_clicks"),
)
def update(_):
seen["triggered"] = dash.ctx.triggered
seen["args_grouping"] = [
(g["str_id"], g["triggered"]) for g in dash.ctx.args_grouping
]
return "clicked"

clicked = '{"index":"caf\u00e9","type":"btn"}'
other = '{"index":"abc","type":"btn"}'
out_id = {"type": "out", "index": "caf\u00e9"}
body = {
"output": create_callback_id(Output(out_id, "children"), []),
"outputs": {"id": out_id, "property": "children"},
"inputs": [
[
{"id": json.loads(clicked), "property": "n_clicks", "value": 2},
{"id": json.loads(other), "property": "n_clicks", "value": 1},
]
],
"changedPropIds": [clicked + ".n_clicks"],
"state": [],
}
response = app.server.test_client().post("/_dash-update-component", json=body)

assert response.status_code == 200
assert seen["triggered"] == [{"prop_id": clicked + ".n_clicks", "value": 2}]
assert seen["args_grouping"] == [(clicked, True), (other, False)]
assert response.get_json()["response"] == {
'{"index":"caf\u00e9","type":"out"}': {"children": "clicked"}
}