Skip to content

Commit f3f6080

Browse files
committed
fix: behavior when patch removes null uneditable fields
1 parent fa4bd81 commit f3f6080

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

scim2_server/operators.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,16 +258,17 @@ class RemoveOperator(Operator):
258258
@classmethod
259259
def operation(cls, model: BaseModel, attribute: str, value: Any):
260260
alias = get_by_alias(type(model), attribute)
261-
existing_value = getattr(model, alias)
262-
if not existing_value:
263-
return
264261

265262
if model.get_field_annotation(alias, Mutability) in (
266263
Mutability.read_only,
267264
Mutability.immutable,
268265
):
269266
raise SCIMException(Error.make_mutability_error())
270267

268+
existing_value = getattr(model, alias)
269+
if not existing_value:
270+
return
271+
271272
if model.get_field_annotation(alias, Required) == Required.true:
272273
raise SCIMException(Error.make_invalid_value_error())
273274

tests/test_operators.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,16 @@ def test_simple_remove_operator_immutable(self):
451451
with pytest.raises(SCIMException, match="immutable"):
452452
RemoveOperator.operation(u, "groups", None)
453453

454+
def test_remove_operator_mutability_validation_on_empty_fields(self):
455+
"""Test that mutability constraints are enforced even on empty/unset fields."""
456+
u = User(id="123") # groups field is None/empty by default
457+
with pytest.raises(SCIMException, match="mutability"):
458+
RemoveOperator.operation(u, "groups", None)
459+
460+
u2 = User() # id field is None/empty by default
461+
with pytest.raises(SCIMException, match="mutability"):
462+
RemoveOperator.operation(u2, "id", None)
463+
454464
def test_remove_operator_root_object(self):
455465
u = User()
456466
with pytest.raises(SCIMException, match="noTarget"):

0 commit comments

Comments
 (0)