File tree 1 file changed +1
-14
lines changed 1 file changed +1
-14
lines changed Original file line number Diff line number Diff line change 4
4
BaseModel ,
5
5
PrivateAttr ,
6
6
ConfigDict ,
7
- model_validator ,
8
7
)
9
- from bson import ObjectId
10
8
11
9
12
10
class ApiBaseModel (BaseModel , ABC ):
13
- _id : Optional [ObjectId ] = PrivateAttr (default = None )
11
+ _id : Optional [str ] = PrivateAttr (default = None )
14
12
model_config = ConfigDict (
15
13
extra = "allow" ,
16
14
use_enum_values = True ,
@@ -25,17 +23,6 @@ def set_id(self, value):
25
23
def get_id (self ):
26
24
return self ._id
27
25
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
-
39
26
@property
40
27
@abstractmethod
41
28
def NAME (): # pylint: disable=invalid-name, no-method-argument
You can’t perform that action at this time.
0 commit comments