File tree 1 file changed +3
-8
lines changed
django_mongodb_backend/fields
1 file changed +3
-8
lines changed Original file line number Diff line number Diff line change @@ -22,22 +22,17 @@ def deconstruct(self):
22
22
return name , path , args , kwargs
23
23
24
24
def get_prep_value (self , value ):
25
- if value is None or isinstance (value , ObjectId ):
26
- return value
27
- try :
28
- return ObjectId (value )
29
- except errors .InvalidId as e :
30
- raise ValueError (f"Field '{ self .name } ' expected an ObjectId but got { value !r} ." ) from e
25
+ return self .to_python (value )
31
26
32
27
def get_internal_type (self ):
33
28
return "ObjectIdAutoField"
34
29
35
30
def to_python (self , value ):
36
- if value is None or isinstance ( value , int ) :
31
+ if value is None :
37
32
return value
38
33
try :
39
34
return ObjectId (value )
40
- except errors .InvalidId :
35
+ except ( errors .InvalidId , TypeError ) :
41
36
raise exceptions .ValidationError (
42
37
self .error_messages ["invalid" ],
43
38
code = "invalid" ,
You can’t perform that action at this time.
0 commit comments