Skip to content

Commit 636455e

Browse files
committed
tests: add unit tests
1 parent d261826 commit 636455e

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

doc/changelog.rst

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

4+
[0.6.5] - 2026-03-10
5+
--------------------
6+
7+
Fixed
8+
^^^^^
9+
- Fix extension serialization crash when an extension is declared but not populated on a resource serialized outside of SCIM context (e.g. FastAPI ``response_model``). :pr:`131`
10+
411
[0.6.4] - 2026-02-05
512
--------------------
613

scim2_models/resources/resource.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,11 @@ def _extension_serializer(
117117
For instance, attributes 'meta', 'id' or 'schemas' should not be
118118
dumped when the model is used as an extension for another model.
119119
"""
120-
partial_result = handler(value)
121-
122-
if partial_result is None:
120+
if value is None:
123121
return None
124122

123+
partial_result = handler(value)
124+
125125
result = {
126126
attr_name: value
127127
for attr_name, value in partial_result.items()

tests/test_resource_extension.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import datetime
22

33
import pytest
4+
from pydantic import TypeAdapter
45

56
from scim2_models import URN
67
from scim2_models import Context
@@ -370,6 +371,14 @@ def test_class_getitem():
370371
User[int]
371372

372373

374+
def test_dump_resource_with_unset_extension():
375+
"""Serialize a resource whose extension is declared but not populated."""
376+
user = User[EnterpriseUser](user_name="bjensen")
377+
ta = TypeAdapter(User[EnterpriseUser])
378+
payload = ta.dump_python(user)
379+
assert "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User" not in payload
380+
381+
373382
def test_model_attribute_to_scim_attribute_error():
374383
"""Test error case where get_field_root_type returns None."""
375384
from pydantic import Field

0 commit comments

Comments
 (0)