From 7da32d395a4da4c5eab6abf6952239b550a80d3f Mon Sep 17 00:00:00 2001 From: Naq Date: Wed, 11 Mar 2026 18:35:49 +0200 Subject: [PATCH] fix: Allow empty array for ListResponse Resources when totalResults is non-zero --- scim2_models/messages/list_response.py | 2 +- tests/test_list_response.py | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/scim2_models/messages/list_response.py b/scim2_models/messages/list_response.py index 41ca070..e2e0d3e 100644 --- a/scim2_models/messages/list_response.py +++ b/scim2_models/messages/list_response.py @@ -60,7 +60,7 @@ def check_results_number( "Field 'total_results' is required but value is missing or null", ) - if obj.total_results > 0 and not obj.resources: + if obj.total_results > 0 and obj.resources is None: raise PydanticCustomError( "no_resource_error", "Field 'resources' is missing or null but 'total_results' is non-zero.", diff --git a/tests/test_list_response.py b/tests/test_list_response.py index e516fa6..24cef07 100644 --- a/tests/test_list_response.py +++ b/tests/test_list_response.py @@ -186,10 +186,7 @@ def test_zero_results(): ListResponse[User].model_validate(payload, scim_ctx=Context.RESOURCE_QUERY_RESPONSE) payload = {"totalResults": 1, "Resources": []} - with pytest.raises(ValidationError): - ListResponse[User].model_validate( - payload, scim_ctx=Context.RESOURCE_QUERY_RESPONSE - ) + ListResponse[User].model_validate(payload, scim_ctx=Context.RESOURCE_QUERY_RESPONSE) payload = {"totalResults": 1} with pytest.raises(ValidationError):