Skip to content

Allow empty array for Resources when totalResults is non-zero#133

Merged
azmeuk merged 1 commit intopython-scim:mainfrom
NaqGuug:fix/ListResponse-Check
Mar 12, 2026
Merged

Allow empty array for Resources when totalResults is non-zero#133
azmeuk merged 1 commit intopython-scim:mainfrom
NaqGuug:fix/ListResponse-Check

Conversation

@NaqGuug
Copy link
Copy Markdown
Contributor

@NaqGuug NaqGuug commented Mar 11, 2026

As said in the rfc and in the docstring, resources must be set if totalResults is non-zero. However, scim2-models does not accept an empty list because in Python it is considered as falsy value.

This is fixed by checking if resources is None. That's it.

@azmeuk
Copy link
Copy Markdown
Member

azmeuk commented Mar 12, 2026

Per RFC7644 3.4.2:

Resources A multi-valued list of complex objects containing the
requested resources. This MAY be a subset of the full set of
resources if pagination (Section 3.4.2.4) is requested. REQUIRED
if "totalResults" is non-zero.

What do you think is wrong with the current code?

if obj.total_results > 0 and not obj.resources:

If totalResults is 1 or more, then the resources must be non empty. [] is not a valid value since totalResults is >0 anyway.

@NaqGuug
Copy link
Copy Markdown
Contributor Author

NaqGuug commented Mar 12, 2026

There are two common cases where the totalResults is one or more but resources is an empty array.

  1. Querying resources with count set to 0.
  2. Setting startIndex greater than there are resources.

The main thing here is the first scenario. You can query how many resources the endpoint have without receiving the resources by setting count to 0. This is especially useful when the server has thousands of resources and it takes a long time to process all of them.

I think that is the main reason why in the rfc the minimum value for count is 0.

If totalResults is 1 or more, then the resources must be non empty.

Resources must be set, empty array still counts. Not defining resources or setting it null is invalid.

@azmeuk
Copy link
Copy Markdown
Member

azmeuk commented Mar 12, 2026

Oh. Nice catch.

@azmeuk azmeuk merged commit 738ae77 into python-scim:main Mar 12, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants