Skip to content

Commit d988e45

Browse files
committed
fix: refuse the resource parameter removed from delete and modify
1 parent 57bcce4 commit d988e45

3 files changed

Lines changed: 31 additions & 0 deletions

File tree

‎doc/changelog.rst‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
Changelog
22
=========
33

4+
[0.13.1] - Unreleased
5+
---------------------
6+
7+
Fixed
8+
^^^^^
9+
- Until 1.0, ``delete`` and ``modify`` raise a :class:`TypeError` when they are given the
10+
``resource`` parameter removed in 0.13. It used to be passed to the HTTP library, and the request
11+
failed with a misleading "No resource type" error.
12+
413
[0.13.0] - 2026-10-08
514
---------------------
615

‎scim2_client/client.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,19 @@
8080
_ME_ENDPOINT = "/Me"
8181

8282

83+
def _refuse_resource_parameter(operation: str, kwargs: dict[str, Any]) -> None:
84+
"""Refuse the ``resource`` parameter that ``delete`` and ``modify`` took until 0.12.
85+
86+
It would otherwise be passed to the HTTP library, and the request would lack its target.
87+
Will be removed in 1.0.
88+
"""
89+
if "resource" in kwargs:
90+
raise TypeError(
91+
f"{operation}() got an unexpected keyword argument 'resource'. "
92+
"Pass the resource as target."
93+
)
94+
95+
8396
class _Me:
8497
"""The resource of the authenticated client, reached under ``/Me`` (:rfc:`RFC 7644 §3.11 <7644#section-3.11>`).
8598
@@ -1506,6 +1519,7 @@ def _prepare_delete_request(
15061519
expected_status_codes: list[int] | None = None,
15071520
**kwargs: Any,
15081521
) -> RequestPayload:
1522+
_refuse_resource_parameter("delete", kwargs)
15091523
url, _, instance = self._locate_resource(target, id, "delete")
15101524
req = RequestPayload(
15111525
expected_status_codes=expected_status_codes,
@@ -1572,6 +1586,7 @@ def _prepare_patch_request(
15721586
**kwargs: Any,
15731587
) -> RequestPayload:
15741588
"""Prepare a PATCH request payload."""
1589+
_refuse_resource_parameter("modify", kwargs)
15751590
# The id is optional, so the patch operation may take its place.
15761591
if not isinstance(id, str | Resource | None):
15771592
if patch_op is not None:

‎tests/test_resource_types.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,13 @@ def test_patch_operation_passed_twice_is_refused(client):
439439
client.modify(User, patch_op, patch_op)
440440

441441

442+
@pytest.mark.parametrize("operation", ["delete", "modify"])
443+
def test_resource_parameter_is_refused(client, operation):
444+
"""The resource parameter removed in 0.13 is refused instead of being passed to the HTTP library."""
445+
with pytest.raises(TypeError, match="Pass the resource as target"):
446+
getattr(client, operation)(resource=User, id="123")
447+
448+
442449
def test_search_reaches_the_resource_type_of_a_model(httpserver, client):
443450
"""Test that a search under a model is sent to the endpoint of its resource type."""
444451
httpserver.expect_request("/Users/.search", method="POST").respond_with_json(

0 commit comments

Comments
 (0)