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
4 changes: 3 additions & 1 deletion mp_api/client/contribs/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}!"
)
Expand Down
16 changes: 16 additions & 0 deletions tests/client/contribs/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})