@@ -649,6 +649,20 @@ def __init__(
649649 "as integers"
650650 )
651651
652+ if self .scale is not None :
653+ # Range-check scale before the precision=0 fallback below, so a clearly
654+ # invalid scale is reported rather than hidden behind a migration warning.
655+ if self .scale < 0 :
656+ raise ValueError (
657+ "DecimalParameter scale must be >= 0, got {}" .format (self .scale )
658+ )
659+ if self .scale > self .MAX_PRECISION :
660+ raise ValueError (
661+ "DecimalParameter scale must be between 0 and {}, got {}" .format (
662+ self .MAX_PRECISION , self .scale
663+ )
664+ )
665+
652666 if self .precision == 0 :
653667 # Earlier releases treated precision=0 as falsy, i.e. "unset", and inferred
654668 # the type from the value. Keep that behaviour for now (swapping e.g.
@@ -671,23 +685,13 @@ def __init__(
671685 # Range-check the raw arguments *before* the legacy swap below, so a call
672686 # that is simply invalid (rather than written for the legacy convention)
673687 # gets an error naming the argument the caller actually passed, and no
674- # misleading migration warning.
675- if self .scale < 0 :
676- raise ValueError (
677- "DecimalParameter scale must be >= 0, got {}" .format (self .scale )
678- )
688+ # misleading migration warning. (scale was range-checked above.)
679689 if not 1 <= self .precision <= self .MAX_PRECISION :
680690 raise ValueError (
681691 "DecimalParameter precision must be between 1 and {}, got {}" .format (
682692 self .MAX_PRECISION , self .precision
683693 )
684694 )
685- if self .scale > self .MAX_PRECISION :
686- raise ValueError (
687- "DecimalParameter scale must be between 0 and {}, got {}" .format (
688- self .MAX_PRECISION , self .scale
689- )
690- )
691695
692696 if self .scale == 0 and self .precision is not None :
693697 # Earlier releases also treated scale=0 as falsy, i.e. "unset", and
0 commit comments