From 1ae3f317977d1581e2d192d09fa9b379c8f670c5 Mon Sep 17 00:00:00 2001 From: Pieterjan Robbe Date: Fri, 20 Nov 2026 15:46:54 -0800 Subject: [PATCH] fix(contribs): init_columns no longer flags prefix-named siblings as duplicates The duplicate check used col.startswith(k), so a column like a.b was rejected when a sibling a.bc had already been scanned. Match on the '.' separator instead; true duplicates (ancestor after child) still raise. --- mp_api/client/contribs/client.py | 4 +++- tests/client/contribs/test_client.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/mp_api/client/contribs/client.py b/mp_api/client/contribs/client.py index cdbe30e1..5c9db55f 100644 --- a/mp_api/client/contribs/client.py +++ b/mp_api/client/contribs/client.py @@ -1183,7 +1183,9 @@ def init_columns( ) for col in scanned_columns: - if nesting and col.startswith(k): + # match on the "." separator so that e.g. "a.b" is not + # flagged as a duplicate of a sibling "a.bc" + if nesting and col.startswith(f"{k}."): raise MPContribsClientError( f"Duplicate definition of {k} in {col}!" ) diff --git a/tests/client/contribs/test_client.py b/tests/client/contribs/test_client.py index d1cbf095..cbbc403c 100644 --- a/tests/client/contribs/test_client.py +++ b/tests/client/contribs/test_client.py @@ -57,3 +57,19 @@ def test_mock(): with pytest.raises(ValueError): with ContribsClient(host="not.valid.org") as client: spec = client.swagger_spec + + +def test_init_columns_prefix_is_not_duplicate(): + from mp_api.client.core.exceptions import MPContribsClientError + + client = MagicMock(project="demo") + client.projects.getProjectByName.return_value.result.return_value = {"columns": []} + + # sibling columns where one name is a prefix of the other + ContribsClient.init_columns(client, {"a.bc": "", "a.b": None}) + payload = client.projects.updateProjectByName.call_args.kwargs["project"] + assert {c["path"] for c in payload["columns"]} == {"data.a.b", "data.a.bc"} + + # a true duplicate (ancestor listed after its child) is still rejected + with pytest.raises(MPContribsClientError, match="Duplicate definition"): + ContribsClient.init_columns(client, {"a.b.c": "", "a.b": None})