From 0ec9d0652aa254e2814590253742a8b1666df64a Mon Sep 17 00:00:00 2001 From: shreeraj Date: Fri, 20 Nov 2026 14:22:26 +0530 Subject: [PATCH] Don't apply debugpy.configure() properties when the call fails configure() validated and stored its properties one at a time, so a call that raised ValueError for one property still applied the properties that came before it. For example, configure({"qt": "auto", "subProcess": "yes"}) raised "'subProcess' must be a bool" but left qt set to "auto", and the next listen() would go on to enable Qt support the caller never got to configure. Validate every property first and only then update the configuration, so a failed call leaves it unchanged. --- src/debugpy/server/api.py | 5 ++++- tests/debugpy/server/test_api.py | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/debugpy/server/api.py b/src/debugpy/server/api.py index 2772ab57e..54664fca7 100644 --- a/src/debugpy/server/api.py +++ b/src/debugpy/server/api.py @@ -81,6 +81,8 @@ def configure(properties=None, **kwargs): properties = dict(properties) properties.update(kwargs) + # Validate everything before changing anything, so that a call which raises + # leaves the existing configuration untouched. for k, v in properties.items(): if k not in _config: raise ValueError("Unknown property {0!r}".format(k)) @@ -90,7 +92,8 @@ def configure(properties=None, **kwargs): valid_values = _config_valid_values.get(k) if (valid_values is not None) and (v not in valid_values): raise ValueError("{0!r} must be one of: {1!r}".format(k, valid_values)) - _config[k] = v + + _config.update(properties) def _starts_debugging(func): diff --git a/tests/debugpy/server/test_api.py b/tests/debugpy/server/test_api.py index f8bd7b581..e4dd2dfd1 100644 --- a/tests/debugpy/server/test_api.py +++ b/tests/debugpy/server/test_api.py @@ -82,3 +82,25 @@ def test_listen_empty_adapter_read_raises(monkeypatch): str(exc_info.value) == "error retrieving adapter endpoints: EOF while reading adapter endpoints" ) + + +@pytest.mark.parametrize( + "properties", + [ + {"qt": "auto", "subProcess": "yes"}, + {"qt": "pyside", "unknown": 1}, + {"subProcess": False, "qt": "not-a-qt-mode"}, + ], + ids=["bad-type", "unknown-property", "bad-value"], +) +def test_configure_failure_leaves_config_unchanged(monkeypatch, properties): + # configure() raises ValueError for a property it cannot accept. When it does, + # none of the other properties passed in the same call may have been applied, + # or the caller is left with a configuration it never asked for. + monkeypatch.setattr(api, "ensure_logging", lambda: None) + monkeypatch.setattr(api, "_config", {"qt": "none", "subProcess": True}) + + with pytest.raises(ValueError): + api.configure(properties) + + assert api._config == {"qt": "none", "subProcess": True}