Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QuerySet.count() method is broken on Django 1.8 #100

Open
dan-passaro opened this issue Oct 1, 2015 · 3 comments
Open

QuerySet.count() method is broken on Django 1.8 #100

dan-passaro opened this issue Oct 1, 2015 · 3 comments

Comments

@dan-passaro
Copy link

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.

@mwatchi
Copy link

mwatchi commented Dec 24, 2015

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']

@fizxmike
Copy link

fizxmike commented Feb 5, 2016

Bump

@dan-passaro
Copy link
Author

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 👍

@dlo dlo added the help wanted label Feb 1, 2018
@dlo dlo added the bug label Mar 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants