@@ -140,7 +140,7 @@ def to_python(self, value):
140140 pass
141141 return value
142142
143- def validate (self , value ):
143+ def validate (self , value , clean = True ):
144144 if not isinstance (value , str ):
145145 self .error ("StringField only accepts string values" )
146146
@@ -212,7 +212,7 @@ def __init__(self, url_regex=None, schemes=None, **kwargs):
212212 self .schemes = schemes or self ._URL_SCHEMES
213213 super ().__init__ (** kwargs )
214214
215- def validate (self , value ):
215+ def validate (self , value , clean = True ):
216216 # Check first if the scheme is valid
217217 scheme = value .split ("://" )[0 ].lower ()
218218 if scheme not in self .schemes :
@@ -301,7 +301,7 @@ def validate_domain_part(self, domain_part):
301301
302302 return False
303303
304- def validate (self , value ):
304+ def validate (self , value , clean = True ):
305305 super ().validate (value )
306306
307307 if "@" not in value :
@@ -351,7 +351,7 @@ def to_python(self, value):
351351 pass
352352 return value
353353
354- def validate (self , value ):
354+ def validate (self , value , clean = True ):
355355 try :
356356 value = int (value )
357357 except (TypeError , ValueError ):
@@ -389,7 +389,7 @@ def to_python(self, value):
389389 pass
390390 return value
391391
392- def validate (self , value ):
392+ def validate (self , value , clean = True ):
393393 if isinstance (value , int ):
394394 try :
395395 value = float (value )
@@ -480,7 +480,7 @@ def to_mongo(self, value):
480480 return str (self .to_python (value ))
481481 return float (self .to_python (value ))
482482
483- def validate (self , value ):
483+ def validate (self , value , clean = True ):
484484 if not isinstance (value , decimal .Decimal ):
485485 if not isinstance (value , str ):
486486 value = str (value )
@@ -511,7 +511,7 @@ def to_python(self, value):
511511 pass
512512 return value
513513
514- def validate (self , value ):
514+ def validate (self , value , clean = True ):
515515 if not isinstance (value , bool ):
516516 self .error ("BooleanField only accepts boolean values" )
517517
@@ -532,7 +532,7 @@ class DateTimeField(BaseField):
532532 need accurate microsecond support.
533533 """
534534
535- def validate (self , value ):
535+ def validate (self , value , clean = True ):
536536 new_value = self .to_mongo (value )
537537 if not isinstance (new_value , (datetime .datetime , datetime .date )):
538538 self .error ('cannot parse date "%s"' % value )
@@ -668,7 +668,7 @@ def _convert_from_datetime(self, val):
668668 stored in MongoDB). This is the reverse function of
669669 `_convert_from_string`.
670670
671- >>> a = datetime(2011, 6, 8, 20, 26, 24, 92284)
671+ >>> a = datetime.datetime (2011, 6, 8, 20, 26, 24, 92284)
672672 >>> ComplexDateTimeField()._convert_from_datetime(a)
673673 '2011,06,08,20,26,24,092284'
674674 """
@@ -710,7 +710,7 @@ def __set__(self, instance, value):
710710 else :
711711 instance ._data [self .name ] = value
712712
713- def validate (self , value ):
713+ def validate (self , value , clean = True ):
714714 value = self .to_python (value )
715715 if not isinstance (value , datetime .datetime ):
716716 self .error ("Only datetime objects may used in a ComplexDateTimeField" )
@@ -799,6 +799,7 @@ def lookup_member(self, member_name):
799799 field = doc_type ._fields .get (member_name )
800800 if field :
801801 return field
802+ return None
802803
803804 def prepare_query_value (self , op , value ):
804805 if value is not None and not isinstance (value , self .document_type ):
@@ -958,7 +959,7 @@ def __get__(self, instance, owner):
958959 pk = val ['_ref' ].id )
959960 return super ().__get__ (instance , owner )
960961
961- def validate (self , value ):
962+ def validate (self , value , clean = True ):
962963 """Make sure that a list of valid fields is being used."""
963964 if not isinstance (value , (list , tuple , BaseQuerySet )):
964965 self .error ("Only lists and tuples may be used in a list field" )
@@ -1067,7 +1068,7 @@ def __init__(self, field=None, *args, **kwargs):
10671068 kwargs .setdefault ("default" , dict )
10681069 super ().__init__ (* args , field = field , ** kwargs )
10691070
1070- def validate (self , value ):
1071+ def validate (self , value , clean = True ):
10711072 """Make sure that a list of valid fields is being used."""
10721073 if isinstance (value , (Document ,)):
10731074 value = value .to_mongo ().to_dict ()
@@ -1226,7 +1227,7 @@ def prepare_query_value(self, op, value):
12261227 super ().prepare_query_value (op , value )
12271228 return self .to_mongo (value )
12281229
1229- def validate (self , value ):
1230+ def validate (self , value , clean = True ):
12301231
12311232 if not isinstance (value , (self .document_type , DBRef , ObjectId )):
12321233 self .error (
@@ -1277,7 +1278,7 @@ def __get__(self, instance, owner):
12771278 return LazyReference (document_type = _DocumentRegistry .get (val ['_cls' ]), pk = val ['_ref' ].id , passthrough = True )
12781279 return super ().__get__ (instance , owner )
12791280
1280- def validate (self , value ):
1281+ def validate (self , value , clean = True ):
12811282 if not isinstance (value , (Document , DBRef , dict , SON )):
12821283 self .error ("GenericReferences can only contain documents" )
12831284
@@ -1343,7 +1344,7 @@ def __set__(self, instance, value):
13431344 def to_mongo (self , value ):
13441345 return Binary (value )
13451346
1346- def validate (self , value ):
1347+ def validate (self , value , clean = True ):
13471348 if not isinstance (value , (bytes , Binary )):
13481349 self .error (
13491350 "BinaryField only accepts instances of "
@@ -1407,7 +1408,7 @@ def __init__(self, enum, **kwargs):
14071408 kwargs ["choices" ] = list (self ._enum_cls ) # Implicit validator
14081409 super ().__init__ (** kwargs )
14091410
1410- def validate (self , value ):
1411+ def validate (self , value , clean = True ):
14111412 if isinstance (value , self ._enum_cls ):
14121413 return super ().validate (value )
14131414 try :
@@ -1544,7 +1545,7 @@ async def afs(self) -> gridfs.AsyncGridFS:
15441545 self ._afs = gridfs .AsyncGridFS (await async_get_db (self .db_alias ), self .collection_name )
15451546 return self ._afs
15461547
1547- def get (self , grid_id = None ) -> GridOut :
1548+ def get (self , grid_id = None ) -> GridOut | None :
15481549 if grid_id :
15491550 self .grid_id = grid_id
15501551
@@ -1558,7 +1559,7 @@ def get(self, grid_id=None) -> GridOut:
15581559 # File has been deleted
15591560 return None
15601561
1561- async def aget (self , grid_id = None ) -> AsyncGridOut :
1562+ async def aget (self , grid_id = None ) -> AsyncGridOut | None :
15621563 if grid_id :
15631564 self .grid_id = grid_id
15641565
@@ -1768,7 +1769,7 @@ def to_python(self, value):
17681769 value , collection_name = self .collection_name , db_alias = self .db_alias
17691770 )
17701771
1771- def validate (self , value ):
1772+ def validate (self , value , clean = True ):
17721773 if value .grid_id is not None :
17731774 if not isinstance (value , self .proxy_class ):
17741775 self .error ("FileField only accepts GridFSProxy values" )
@@ -2324,7 +2325,7 @@ def prepare_query_value(self, op, value):
23242325 return None
23252326 return self .to_mongo (value )
23262327
2327- def validate (self , value ):
2328+ def validate (self , value , clean = True ):
23282329 if value is None :
23292330 return
23302331
@@ -2347,7 +2348,7 @@ class GeoPointField(BaseField):
23472348
23482349 _geo_index = pymongo .GEO2D
23492350
2350- def validate (self , value ):
2351+ def validate (self , value , clean = True ):
23512352 """Make sure that a geo-value is of type (x, y)"""
23522353 if not isinstance (value , (list , tuple )):
23532354 self .error ("GeoPointField can only accept tuples or lists of (x, y)" )
@@ -2511,7 +2512,7 @@ def to_python(self, value):
25112512 return None
25122513 return self .to_mongo (value ).to_decimal ()
25132514
2514- def validate (self , value ):
2515+ def validate (self , value , clean = True ):
25152516 if not isinstance (value , Decimal128 ):
25162517 try :
25172518 value = Decimal128 (value )
0 commit comments