django-pyodbc
django-pyodbc copied to clipboard
QuerySet.count() method is broken on Django 1.8
I get this traceback when trying to execute a Model.objects.count()
with django-pyodbc 0.3.0 and Django 1.8.4.
[...]/local/lib/python2.7/site-packages/django_pyodbc/compiler.pyc in _fix_aggregates(self)
116 """
117 for alias, aggregate in self.query.aggregate_select.items():
--> 118 if aggregate.sql_function == 'AVG':# and self.connection.cast_avg_to_float:
119 # Embed the CAST in the template on this query to
120 # maintain multi-db support.
AttributeError: 'Count' object has no attribute 'sql_function'
I do not get this same error when using Django 1.7.10.
Same issue with other aggreagate functions like Max and Min
You can patch it by setting it to this:
if type(aggregate) == django.db.models.aggregates.Max: #.sql_function == 'AVG':
But thte aggregates construct doesn't have enough types to map to all the handlings in MSSQL.
dir(django.db.models.aggregates) ['Aggregate', 'Avg', 'Count', 'FieldError', 'FloatField', 'Func', 'IntegerField', 'Max', 'Min', 'StdDev', 'Sum', 'Value', 'Variance', 'all', 'builtins', 'doc', 'file', 'name', 'package']
Bump
For whom it may help, we switched to django-pyodbc-azure. It is kept much more up to date than this lib and is not tied to Azure in any special way, despite the name. Highly recommended 👍