mssql-django 1.7.4 is now available on PyPI.
This release focused on two fixes in raw and annotated GROUP BY query handling.
What is fixed
1) Escaped %% handling in GROUP BY params
GROUP BY queries that mixed escaped %% literals with real params could raise IndexError.
In 1.7.4, placeholder rewriting now only touches %% and %s in the intended paths. These queries now execute correctly instead of failing.
Example:
from django.db import connection
sql = """
SELECT LEFT(name, %s) AS prefix, COUNT(*)
FROM testapp_customer_name
WHERE notes LIKE 'promo%%'
GROUP BY LEFT(name, %s)
"""
params = [3, 3]
with connection.cursor() as cursor:
cursor.execute(sql, params)
rows = cursor.fetchall()
Before 1.7.4: this pattern could raise IndexError when escaped %% and %s placeholders appeared together.
In 1.7.4: the query executes and returns grouped rows as expected.
2) IntegerChoices in raw GROUP BY queries
Passing IntegerChoices values into raw GROUP BY queries could raise NotImplementedError.
In 1.7.4, type checks use isinstance, so IntegerChoices params are handled correctly while bool and plain int behavior stays consistent.
Example:
from django.db import connection
from django.db.models import IntegerChoices
class Priority(IntegerChoices):
LOW = 1, "Low"
HIGH = 2, "High"
sql = """
SELECT priority, COUNT(*)
FROM testapp_choice_question
WHERE priority = %s
GROUP BY priority
"""
with connection.cursor() as cursor:
cursor.execute(sql, [Priority.HIGH])
rows = cursor.fetchall()
Before 1.7.4: passing Priority.HIGH could raise NotImplementedError.
In 1.7.4: IntegerChoices values bind correctly in raw GROUP BY queries.
Tests
This release also adds regression coverage for:
- Escaped %% and unescaped % GROUP BY paths
- IntegerChoices in raw GROUP BY queries
Compatibility
mssql-django 1.7.4 remains a backward-compatible patch release with no breaking changes.
Thank you
Thanks to everyone using mssql-django, especially those that reported these issues. Your reports and repros help improve reliability with every patch.
If you hit an issue, please open one here: https://github.com/microsoft/mssql-django/issues
PyPI: https://pypi.org/project/mssql-django/
Release notes: https://github.com/microsoft/mssql-django/releases/tag/1.7.4