FIX: support IntegerChoices params in raw GROUP BY queries (#540) - #541
Merged
Merged
Conversation
_as_sql_type used exact type checks (typ == int / typ == bool), so an IntegerChoices value (an int subclass) missed the int branch and hit NotImplementedError whenever a raw query contained a GROUP BY. switched both branches to isinstance and moved the bool check above int, since bool is itself an int subclass. Issue: #540 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a regression in the SQL Server backend’s raw GROUP BY parameter handling so that models.IntegerChoices values (which are int subclasses) can be bound without raising NotImplementedError.
Changes:
- Update
CursorWrapper._as_sql_type()to useisinstance(..., bool)/isinstance(..., int)soIntegerChoicesmembers are treated as integers, withboolhandled first. - Add a regression test that executes a raw
GROUP BYquery with anIntegerChoicesargument.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
mssql/base.py |
Adjusts SQL type inference for GROUP BY parameter declaration to accept int subclasses (including IntegerChoices) and keep bool mapping to BIT. |
testapp/tests/test_queries.py |
Adds a regression test ensuring raw GROUP BY queries accept IntegerChoices parameters without error. |
jahnvi480
approved these changes
Jul 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
raw query with a GROUP BY clause plus an IntegerChoices arg raised NotImplementedError:
root cause: any query containing GROUP BY goes through
format_group_by_params, which types each param and calls_as_sql_type. that function used exact type checks (typ == int), andtype(IntegerChoices_value)is the enum class, notint. even though it subclasses int,enum_cls == intis False, so it fell through to the raise. plain ints and the ORM path never hit this. regression from #354.fix: switch the int/bool branches to
isinstance. bool moves above int because bool is itself an int subclass and must not fall into the int branch.verified against SQL Server 2022:
added a regression test (
TestIntegerChoicesGroupby) that fails without the fix with the exact NotImplementedError above.Closes #540