File tree Expand file tree Collapse file tree 1 file changed +5
-1
lines changed Expand file tree Collapse file tree 1 file changed +5
-1
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,10 @@ def get_prep_value(self, value):
23
23
# like settings.SITE_ID which has a system check requiring an integer.
24
24
if isinstance (value , (ObjectId | int )):
25
25
return value
26
+ # If a digit doesn't match the length of an ObjectId, treat it as an
27
+ # integer. Manually assigned IDs won't be 24 digits long.
28
+ if isinstance (value , str ) and value .isdigit () and len (value ) != 24 :
29
+ return int (value )
26
30
try :
27
31
return ObjectId (value )
28
32
except errors .InvalidId as e :
@@ -32,7 +36,7 @@ def rel_db_type(self, connection):
32
36
return Field ().db_type (connection = connection )
33
37
34
38
def to_python (self , value ):
35
- if value is None :
39
+ if value is None or isinstance ( value , int ) :
36
40
return value
37
41
try :
38
42
return ObjectId (value )
You can’t perform that action at this time.
0 commit comments