@@ -70,7 +70,7 @@ class BuiltSchemasDTO:
7070@dataclass (frozen = True )
7171class SchemasInfoDTO :
7272 # id field
73- resource_id_field : Tuple [Type , FieldInfo ]
73+ resource_id_field : Tuple [Type , FieldInfo , Callable ]
7474 # pre-built attributes
7575 attributes_schema : Type [BaseModel ]
7676 # relationships
@@ -233,7 +233,7 @@ def _get_info_from_schema_for_building(
233233 relationships_schema_fields = {}
234234 included_schemas : List [Tuple [str , BaseModel , str ]] = []
235235 has_required_relationship = False
236- resource_id_field = (str , Field (None ))
236+ resource_id_field = (str , Field (None ), None )
237237
238238 for name , field in (schema .__fields__ or {}).items ():
239239 if isinstance (field .field_info .extra .get ("relationship" ), RelationshipInfo ):
@@ -259,7 +259,7 @@ def _get_info_from_schema_for_building(
259259 if not field .field_info .extra .get ("client_can_set_id" ):
260260 continue
261261
262- resource_id_field = (str , Field (cast = field . outer_type_ , ** field .field_info .extra ))
262+ resource_id_field = (str , Field (** field .field_info .extra ), field . outer_type_ )
263263 else :
264264 attributes_schema_fields [name ] = (field .outer_type_ , field .field_info )
265265
@@ -344,15 +344,15 @@ def _build_jsonapi_object(
344344 attributes_schema : Type [TypeSchema ],
345345 relationships_schema : Type [TypeSchema ],
346346 includes ,
347- resource_id_field : Tuple [Type , FieldInfo ],
347+ resource_id_field : Tuple [Type , FieldInfo , Callable ],
348348 model_base : Type [JSONAPIObjectSchemaType ] = JSONAPIObjectSchema ,
349349 use_schema_cache : bool = True ,
350350 relationships_required : bool = False ,
351351 ) -> Type [JSONAPIObjectSchemaType ]:
352352 if use_schema_cache and base_name in self .base_jsonapi_object_schemas_cache :
353353 return self .base_jsonapi_object_schemas_cache [base_name ]
354354
355- field_type , field_info = resource_id_field
355+ field_type , field_info , id_cast_func = resource_id_field
356356
357357 object_jsonapi_schema_fields = {
358358 "attributes" : (attributes_schema , ...),
@@ -369,6 +369,9 @@ def _build_jsonapi_object(
369369 type = (str , Field (default = resource_type or self ._resource_type , description = "Resource type" )),
370370 __base__ = model_base ,
371371 )
372+ if id_cast_func :
373+ object_jsonapi_schema ._id_cast_func = id_cast_func
374+
372375 if use_schema_cache :
373376 self .base_jsonapi_object_schemas_cache [base_name ] = object_jsonapi_schema
374377
0 commit comments