Skip to content

Commit cc4b3ef

Browse files
authored
fix: compatibility with pydantic 2.13 (#142)
1 parent 08382ca commit cc4b3ef

File tree

4 files changed

+190
-167
lines changed

4 files changed

+190
-167
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.11] - 2026-04-13
5+
---------------------
6+
7+
Added
8+
^^^^^
9+
- Compatibility with Pydantic 2.13.
10+
411
[0.6.11] - 2026-04-10
512
---------------------
613

scim2_models/resources/resource.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import copyreg
12
from datetime import datetime
23
from typing import TYPE_CHECKING
34
from typing import Annotated
@@ -409,14 +410,10 @@ def _dedicated_attributes(
409410
"""Return attributes that are not members the parent 'excluded_models'."""
410411

411412
def compare_field_infos(fi1: Any, fi2: Any) -> bool:
412-
return (
413-
fi1
414-
and fi2
415-
and fi1.__slotnames__ == fi2.__slotnames__
416-
and all(
417-
getattr(fi1, attr) == getattr(fi2, attr) for attr in fi1.__slotnames__
418-
)
419-
)
413+
if not fi1 or not fi2:
414+
return False
415+
slot_names = copyreg._slotnames(type(fi1)) # type: ignore[attr-defined]
416+
return all(getattr(fi1, attr) == getattr(fi2, attr) for attr in slot_names)
420417

421418
parent_field_infos = {
422419
field_name: field_info

tests/test_dynamic_schemas.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import copyreg
12
import operator
23

34
import pytest
5+
from pydantic.fields import FieldInfo
46

57
from scim2_models import URN
68
from scim2_models.context import Context
@@ -155,6 +157,25 @@ class Bar(Foo):
155157
}
156158

157159

160+
def test_to_schema_without_slotnames_cache():
161+
"""Regression test for ``FieldInfo.__slotnames__`` usage.
162+
163+
``FieldInfo.__slotnames__`` is a cache populated lazily by ``copy.copy`` /
164+
``copyreg._slotnames``. Computing a schema must not rely on that cache
165+
being already warm, otherwise ``to_schema`` raises ``AttributeError`` on a
166+
fresh process.
167+
"""
168+
copyreg._slotnames(FieldInfo)
169+
del FieldInfo.__slotnames__
170+
171+
class Foo(Resource):
172+
__schema__ = URN("urn:ietf:params:scim:schemas:core:2.0:Foo")
173+
174+
foo: str | None = None
175+
176+
Foo.to_schema()
177+
178+
158179
def test_make_python_model_validates_name():
159180
"""Test that make_python_model raises an exception when obj.name is not defined."""
160181
# Test with Schema object without name

0 commit comments

Comments
 (0)