Skip to content

Conversation

@VIZZARD-X
Copy link
Contributor

Trac ticket number

ticket-36030

Branch description

SQLite already preserves Decimal values without requiring an explicit
CAST(... AS NUMERIC). However, Django currently applies this CAST
unconditionally in SQLiteNumericMixin, even when the expression is
a simple Value(Decimal).

As reported in ticket #36030, this produces redundant SQL and causes
unnecessary type coercion on SQLite.

Following the discussion on the ticket, this patch updates
SQLiteNumericMixin.as_sqlite() to skip numeric casting when the
expression is Value(Decimal)
, matching SQLite's native behavior.

This change:

  • avoids unnecessary SQL casting,
  • preserves correct numeric behavior,
  • keeps the existing logic for all other DecimalField expressions,
  • requires no changes for other backends.

No new tests are required (ticket metadata: Needs tests: no).

Checklist

  • This PR targets the main branch.
  • The commit message is written in past tense, mentions the ticket number, and ends with a period.
  • I have checked the "Has patch" flag on the Trac ticket.
  • I have added or updated relevant tests.
  • I have added or updated relevant docs, including release notes if applicable.
  • I have attached screenshots in light/dark modes for UI changes (N/A).

@VIZZARD-X VIZZARD-X force-pushed the ticket-36030-sqlite-decimal-cast branch 5 times, most recently from 27059e3 to bb59fec Compare November 22, 2025 13:45
@VIZZARD-X VIZZARD-X force-pushed the ticket-36030-sqlite-decimal-cast branch from bb59fec to 1a320eb Compare November 22, 2025 14:59
@github-actions
Copy link

📊 Coverage Report for Changed Files

-------------
Diff Coverage
Diff: origin/main...HEAD, staged and unstaged changes
-------------
No lines with coverage information in this diff.
-------------


Note: Missing lines are warnings only. Some lines may not be covered by SQLite tests as they are database-specific.

For more information about code coverage on pull requests, see the contributing documentation.

@VIZZARD-X VIZZARD-X closed this by deleting the head repository Nov 24, 2025
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.

1 participant