Skip to content

Commit 97b8aca

Browse files
ai: apply changes for #1006 (1 review thread)
Addresses: - #4418708511 at src/databricks/sql/parameters/native.py:724 Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>
1 parent 1bda507 commit 97b8aca

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

‎src/databricks/sql/parameters/native.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,9 @@ def __init__(
728728
# DECIMAL can never have scale > precision, so this can only be a call
729729
# written for the old convention: keep it working for now (swap the
730730
# arguments) but warn so callers migrate before this becomes an error.
731+
# scale == precision is deliberately *not* handled here: it reads the
732+
# same under both conventions, so it gets the SQL meaning and is widened
733+
# like any correctly ordered call (documented in the CHANGELOG).
731734
warnings.warn(
732735
"DecimalParameter received scale ({}) > precision ({}); interpreting the "
733736
"arguments using the legacy (swapped) convention as DECIMAL({},{}). "

‎tests/unit/test_parameters.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,17 @@ def test_decimal_correct_order_with_more_fractional_digits_is_widened():
214214
assert p._cast_expr() == "DECIMAL(6,4)"
215215

216216

217+
def test_decimal_scale_equal_to_precision_is_widened_without_warning():
218+
"""scale == precision means the same in both conventions, so it is not treated as
219+
a legacy call: it gets the SQL meaning and is widened like any correctly ordered
220+
call (earlier releases bound DECIMAL(2,2) and rounded to 0.12). See CHANGELOG."""
221+
with warnings.catch_warnings():
222+
warnings.simplefilter("error")
223+
p = DecimalParameter(Decimal("0.1234"), scale=2, precision=2)
224+
assert not p._legacy_swapped
225+
assert p._cast_expr() == "DECIMAL(4,4)"
226+
227+
217228
@pytest.mark.parametrize(
218229
"scale,precision,match",
219230
(

0 commit comments

Comments
 (0)