Use _effective_decimal_return_scale in Numeric.result_processor by bysiber · Pull Request #13137 · sqlalchemy/sqlalchemy · GitHub
Skip to content

Use _effective_decimal_return_scale in Numeric.result_processor#13137

Open
bysiber wants to merge 1 commit into
sqlalchemy:mainfrom
bysiber:fix/numeric-decimal-return-scale
Open

Use _effective_decimal_return_scale in Numeric.result_processor#13137
bysiber wants to merge 1 commit into
sqlalchemy:mainfrom
bysiber:fix/numeric-decimal-return-scale

Conversation

@bysiber

@bysiber bysiber commented Feb 20, 2026

Copy link
Copy Markdown
Contributor

Description

Numeric.result_processor computes the decimal return scale inline, bypassing the decimal_return_scale parameter, while Float.result_processor correctly uses _effective_decimal_return_scale.

Current behavior

# Numeric.result_processor - ignores decimal_return_scale
return processors.to_decimal_processor_factory(
    decimal.Decimal,
    (
        self.scale
        if self.scale is not None
        else self._default_decimal_return_scale
    ),
)

The _effective_decimal_return_scale property (from NumericCommon) checks self.decimal_return_scale first, then falls back to self.scale, then _default_decimal_return_scale. The inline logic in Numeric skips the decimal_return_scale check entirely.

This means Numeric(precision=10, scale=2, decimal_return_scale=5) would use scale 2 instead of 5 when the DBAPI doesn't support native decimals.

Fix

Use self._effective_decimal_return_scale, same as Float.result_processor already does.

# After fix - consistent with Float
return processors.to_decimal_processor_factory(
    decimal.Decimal,
    self._effective_decimal_return_scale,
)

Numeric.result_processor was computing the return scale inline,
skipping the decimal_return_scale parameter entirely. Float already
uses _effective_decimal_return_scale which checks decimal_return_scale
first. This brings Numeric in line with Float and honors the
decimal_return_scale parameter as documented.
@CaselIT

CaselIT commented Feb 20, 2026

Copy link
Copy Markdown
Member

@bysiber

bysiber commented Feb 20, 2026

Copy link
Copy Markdown
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants