@@ -22,19 +22,11 @@ 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 :
26
- return None
27
- # Accept int for compatibility with Django's test suite which has many
28
- # instances of manually assigned integer IDs, as well as for things
29
- # like settings.SITE_ID which has a system check requiring an integer.
30
- if isinstance (value , (ObjectId | int )):
25
+ if value is None or isinstance (value , ObjectId ):
31
26
return value
32
27
try :
33
28
return ObjectId (value )
34
29
except errors .InvalidId as e :
35
- # A manually assigned integer ID?
36
- if isinstance (value , str ) and value .isdigit ():
37
- return int (value )
38
30
raise ValueError (f"Field '{ self .name } ' expected an ObjectId but got { value !r} ." ) from e
39
31
40
32
def get_internal_type (self ):
@@ -46,14 +38,11 @@ def to_python(self, value):
46
38
try :
47
39
return ObjectId (value )
48
40
except errors .InvalidId :
49
- try :
50
- return int (value )
51
- except ValueError :
52
- raise exceptions .ValidationError (
53
- self .error_messages ["invalid" ],
54
- code = "invalid" ,
55
- params = {"value" : value },
56
- ) from None
41
+ raise exceptions .ValidationError (
42
+ self .error_messages ["invalid" ],
43
+ code = "invalid" ,
44
+ params = {"value" : value },
45
+ ) from None
57
46
58
47
@cached_property
59
48
def validators (self ):
0 commit comments