0

I am writing a small script in Django. It is based on the Command class for execution by cron. I am using pyodbc with MS-SQL.

class Command(BaseCommand):
    help = 'Sends email notifications'

    def handle(self, *args, **options):
        all_open_port = MyEmailModel.objects.using('emaildb').filter(u_sentinstant__gte=datetime.date.today())

        for p in all_open_port:
            self.stdout.write(p.u_sentinstant)

        self.stdout.write(self.style.SUCCESS('Successfully finished.'))

I alwas get this error, when the QuerySet is evaluated:

AttributeError: 'Query' object has no attribute 'aggregate_select'

I am unable to solve this as the code is identical to the docs...

Traceback:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\site-packages\django\core\management\__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\site-packages\django\core\management\__init__.py", line 359, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\site-packages\django\core\management\base.py", line 294, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\site-packages\django\core\management\base.py", line 345, in execute
    output = self.handle(*args, **options)
  File "C:\Users\user\Desktop\CarrierExchange\cusnotifier\management\commands\sendnotifications.py", line 12, in handle
    for p in all_open_port:
  File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\site-packages\django\db\models\query.py", line 256, in __iter__
    self._fetch_all()
  File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\site-packages\django\db\models\query.py", line 1087, in _fetch_all
    self._result_cache = list(self.iterator())
  File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\site-packages\django\db\models\query.py", line 54, in __iter__
    results = compiler.execute_sql()
  File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\site-packages\django\db\models\sql\compiler.py", line 824, in execute_sql
    sql, params = self.as_sql()
  File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\site-packages\django_pyodbc\compiler.py", line 204, in as_sql
    self._fix_aggregates()
  File "C:\Users\user\AppData\Local\Programs\Python\Python35\lib\site-packages\django_pyodbc\compiler.py", line 180, in _fix_aggregates
    for alias, aggregate in self.query.aggregate_select.items():
AttributeError: 'Query' object has no attribute 'aggregate_select'
3
  • 3
    I believe you need to indent everything after class ... Commented Jun 2, 2017 at 21:10
  • Post the full traceback. The code you have posted does not contain aggregate_select, so the bug is triggered somewhere else in your app. Commented Jun 2, 2017 at 21:47
  • Hi, I posted my Traceback. The code has indent after class but it was removed when I pasted it at stackoverflow. Commented Jun 3, 2017 at 8:19

1 Answer 1

1

Seems to be a bug in latest pyodbc / django-pyodbc: https://github.com/lionheart/django-pyodbc/pull/146/files

Replacing "aggregate_select" with "annotation_select" in "lib\site-packages\django_pyodbc\compiler.py" fixes the problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.