File tree Expand file tree Collapse file tree 1 file changed +1
-14
lines changed Expand file tree Collapse file tree 1 file changed +1
-14
lines changed Original file line number Diff line number Diff line change 44 BaseModel ,
55 PrivateAttr ,
66 ConfigDict ,
7- model_validator ,
87)
9- from bson import ObjectId
108
119
1210class ApiBaseModel (BaseModel , ABC ):
13- _id : Optional [ObjectId ] = PrivateAttr (default = None )
11+ _id : Optional [str ] = PrivateAttr (default = None )
1412 model_config = ConfigDict (
1513 extra = "allow" ,
1614 use_enum_values = True ,
@@ -25,17 +23,6 @@ def set_id(self, value):
2523 def get_id (self ):
2624 return self ._id
2725
28- @model_validator (mode = 'after' )
29- def validate_computed_id (self ):
30- """Validate _id after model instantiation"""
31- if self ._id is not None :
32- if not isinstance (self ._id , ObjectId ):
33- try :
34- self ._id = ObjectId (str (self ._id ))
35- except Exception as e :
36- raise ValueError (f"Invalid ObjectId: { e } " )
37- return self
38-
3926 @property
4027 @abstractmethod
4128 def NAME (): # pylint: disable=invalid-name, no-method-argument
You can’t perform that action at this time.
0 commit comments