@@ -92,8 +92,7 @@ def _validate(self, model_class: Type[Any]) -> None:
9292class ColumnsEqualCondition (Condition ):
9393 """Used to join records by matching column values."""
9494
95- def __init__ (self , origin_column : str ,
96- destination_model_class : Type [Any ],
95+ def __init__ (self , origin_column : str , destination_model_class : Type [Any ],
9796 destination_column : str ):
9897 super ().__init__ ()
9998 self .column = origin_column
@@ -117,13 +116,19 @@ def _types(self) -> Dict[str, type_pb2.Type]:
117116 return {}
118117
119118 def _validate (self , model_class : Type [Any ]) -> None :
120- assert self .column in model_class .schema
119+ if self .column not in model_class .schema :
120+ raise error .ValidationError ('{} is not a column on {}' .format (
121+ self .column , model_class .table ))
121122 origin = model_class .schema [self .column ]
122- assert self .destination_column in self .destination_model_class .schema
123+ if self .destination_column not in self .destination_model_class .schema :
124+ raise error .ValidationError ('{} is not a column on {}' .format (
125+ self .destination_column , self .destination_model_class .table ))
123126 dest = self .destination_model_class .schema [self .destination_column ]
124127
125- assert (origin .field_type () == dest .field_type () and
126- origin .nullable () == dest .nullable ())
128+ if (origin .field_type () != dest .field_type () or
129+ origin .nullable () != dest .nullable ()):
130+ raise error .ValidationError ('Types of {} and {} do not match' .format (
131+ origin .name , dest .name ))
127132
128133
129134class ForceIndexCondition (Condition ):
@@ -155,11 +160,15 @@ def _types(self) -> Dict[str, type_pb2.Type]:
155160 return {}
156161
157162 def _validate (self , model_class : Type [Any ]) -> None :
158- assert self .name in model_class .indexes
159- if self .index :
160- assert self .index == model_class .indexes [self .name ]
163+ if self .name not in model_class .indexes :
164+ raise error .ValidationError ('{} is not an index on {}' .format (
165+ self .name , model_class .table ))
166+ if self .index and self .index != model_class .indexes [self .name ]:
167+ raise error .ValidationError ('{} does not belong to {}' .format (
168+ self .index .name , model_class .table ))
161169
162- assert not model_class .indexes [self .name ].primary
170+ if model_class .indexes [self .name ].primary :
171+ raise error .ValidationError ('Cannot force query using primary index' )
163172
164173
165174class IncludesCondition (Condition ):
@@ -228,9 +237,12 @@ def _types(self) -> Dict[str, type_pb2.Type]:
228237 return {}
229238
230239 def _validate (self , model_class : Type [Any ]) -> None :
231- assert self .name in model_class .relations
232- if self .relation :
233- assert self .relation == model_class .relations [self .name ]
240+ if self .name not in model_class .relations :
241+ raise error .ValidationError ('{} is not a relation on {}' .format (
242+ self .name , model_class .table ))
243+ if self .relation and self .relation != model_class .relations [self .name ]:
244+ raise error .ValidationError ('{} does not belong to {}' .format (
245+ self .relation .name , model_class .table ))
234246
235247 other_model_class = model_class .relations [self .name ].destination
236248 for condition in self ._conditions :
@@ -377,7 +389,9 @@ def _validate(self, model_class: Type[Any]) -> None:
377389 for (column , _ ) in self .orderings :
378390 if isinstance (column , field .Field ):
379391 column = column .name
380- assert column in model_class .schema
392+ if column not in model_class .schema :
393+ raise error .ValidationError ('{} is not a column on {}' .format (
394+ column , model_class .table ))
381395
382396
383397class ComparisonCondition (Condition ):
@@ -417,10 +431,15 @@ def _types(self) -> type_pb2.Type:
417431 return {self ._column_key : self .model_class .schema [self .column ].grpc_type ()}
418432
419433 def _validate (self , model_class : Type [Any ]) -> None :
420- assert self .column in model_class .schema
421- if self .field :
422- assert self .field == model_class .schema [self .column ]
423- assert self .value is not None
434+ if self .column not in model_class .schema :
435+ raise error .ValidationError ('{} is not a column on {}' .format (
436+ self .column , model_class .table ))
437+ if self .field and self .field != model_class .schema [self .column ]:
438+ raise error .ValidationError ('{} does not belong to {}' .format (
439+ self .column , model_class .table ))
440+ if self .value is None :
441+ raise error .ValidationError ('{} does not support NULL' .format (
442+ self .__name__ ))
424443 model_class .schema [self .column ].validate (self .value )
425444
426445
@@ -440,10 +459,14 @@ def _types(self) -> type_pb2.Type:
440459 return {self ._column_key : list_type }
441460
442461 def _validate (self , model_class : Type [Any ]) -> None :
443- assert isinstance (self .value , list )
444- assert self .column in model_class .schema
445- if self .field :
446- assert self .field == model_class .schema [self .column ]
462+ if not isinstance (self .value , list ):
463+ raise error .ValidationError ('{} is not a list' .format (self .value ))
464+ if self .column not in model_class .schema :
465+ raise error .ValidationError ('{} is not a column on {}' .format (
466+ self .column , model_class .table ))
467+ if self .field and self .field != model_class .schema [self .column ]:
468+ raise error .ValidationError ('{} does not belong to {}' .format (
469+ self .column , model_class .table ))
447470 for value in self .value :
448471 model_class .schema [self .column ].validate (value )
449472
@@ -478,9 +501,12 @@ def _types(self) -> type_pb2.Type:
478501 return super ()._types ()
479502
480503 def _validate (self , model_class : Type [Any ]) -> None :
481- assert self .column in model_class .schema
482- if self .field :
483- assert self .field == model_class .schema [self .column ]
504+ if self .column not in model_class .schema :
505+ raise error .ValidationError ('{} is not a column on {}' .format (
506+ self .column , model_class .table ))
507+ if self .field and self .field != model_class .schema [self .column ]:
508+ raise error .ValidationError ('{} does not belong to {}' .format (
509+ self .column , model_class .table ))
484510 model_class .schema [self .column ].validate (self .value )
485511
486512
0 commit comments