@@ -367,38 +367,47 @@ def _get_validators(self, table: sa.Table, c: sa.Column[object]) -> list[Functio
367
367
for constr in table .constraints :
368
368
if not isinstance (constr , sa .CheckConstraint ):
369
369
continue
370
- if isinstance (constr .sqltext , sa .BinaryExpression ):
371
- left = constr .sqltext .left
372
- right = constr .sqltext .right
373
- op = constr .sqltext .operator
374
- if left .expression is c :
375
- if not isinstance (right , sa .BindParameter ) or right .value is None :
376
- continue
377
- if op is operator .ge : # type: ignore[comparison-overlap]
378
- validators .append (func ("minValue" , (right .value ,)))
379
- elif op is operator .gt : # type: ignore[comparison-overlap]
380
- validators .append (func ("minValue" , (right .value + 1 ,)))
381
- elif op is operator .le : # type: ignore[comparison-overlap]
382
- validators .append (func ("maxValue" , (right .value ,)))
383
- elif op is operator .lt : # type: ignore[comparison-overlap]
384
- validators .append (func ("maxValue" , (right .value - 1 ,)))
385
- elif isinstance (left , sa .Function ):
386
- if left .name == "char_length" :
387
- if next (iter (left .clauses )) is not c :
388
- continue
370
+
371
+ if isinstance (constr .sqltext , sa .BooleanClauseList ):
372
+ if constr .sqltext .operator is not operator .and_ : # type: ignore[comparison-overlap]
373
+ continue
374
+ exprs = constr .sqltext .clauses
375
+ else :
376
+ exprs = (constr .sqltext ,)
377
+
378
+ for expr in exprs :
379
+ if isinstance (expr , sa .BinaryExpression ):
380
+ left = expr .left
381
+ right = expr .right
382
+ op = expr .operator
383
+ if left .expression is c :
389
384
if not isinstance (right , sa .BindParameter ) or right .value is None :
390
385
continue
391
386
if op is operator .ge : # type: ignore[comparison-overlap]
392
- validators .append (func ("minLength " , (right .value ,)))
387
+ validators .append (func ("minValue " , (right .value ,)))
393
388
elif op is operator .gt : # type: ignore[comparison-overlap]
394
- validators .append (func ("minLength" , (right .value + 1 ,)))
395
- elif isinstance (constr .sqltext , sa .Function ):
396
- if constr .sqltext .name in ("regexp" , "regexp_like" ):
397
- clauses = tuple (constr .sqltext .clauses )
398
- if clauses [0 ] is not c or not isinstance (clauses [1 ], sa .BindParameter ):
399
- continue
400
- if clauses [1 ].value is None :
401
- continue
402
- validators .append (func ("regex" , (regex (clauses [1 ].value ),)))
389
+ validators .append (func ("minValue" , (right .value + 1 ,)))
390
+ elif op is operator .le : # type: ignore[comparison-overlap]
391
+ validators .append (func ("maxValue" , (right .value ,)))
392
+ elif op is operator .lt : # type: ignore[comparison-overlap]
393
+ validators .append (func ("maxValue" , (right .value - 1 ,)))
394
+ elif isinstance (left , sa .Function ):
395
+ if left .name == "char_length" :
396
+ if next (iter (left .clauses )) is not c :
397
+ continue
398
+ if not isinstance (right , sa .BindParameter ) or right .value is None :
399
+ continue
400
+ if op is operator .ge : # type: ignore[comparison-overlap]
401
+ validators .append (func ("minLength" , (right .value ,)))
402
+ elif op is operator .gt : # type: ignore[comparison-overlap]
403
+ validators .append (func ("minLength" , (right .value + 1 ,)))
404
+ elif isinstance (expr , sa .Function ):
405
+ if expr .name in ("regexp" , "regexp_like" ):
406
+ clauses = tuple (expr .clauses )
407
+ if clauses [0 ] is not c or not isinstance (clauses [1 ], sa .BindParameter ):
408
+ continue
409
+ if clauses [1 ].value is None :
410
+ continue
411
+ validators .append (func ("regex" , (regex (clauses [1 ].value ),)))
403
412
404
413
return validators
0 commit comments