#11916: Extra params + aggregation creates incorrect SQL.
---------------------------------------------------+------------------------
          Reporter:  [email protected]          |         Owner:  tobias
            Status:  assigned                      |     Milestone:  1.2   
         Component:  Database layer (models, ORM)  |       Version:  1.1   
        Resolution:                                |      Keywords:        
             Stage:  Accepted                      |     Has_patch:  1     
        Needs_docs:  0                             |   Needs_tests:  1     
Needs_better_patch:  0                             |  
---------------------------------------------------+------------------------
Comment (by kmtracey):

 The code change to compiler.py in ticket_11916.diff introduces these
 failures into the doctests for aggregation_regress:

 {{{
 ======================================================================
 FAIL: Doctest:
 regressiontests.aggregation_regress.models.__test__.API_TESTS
 ----------------------------------------------------------------------
 Traceback (most recent call last):
   File "C:\u\kmt\django\trunk\django\test\_doctest.py", line 2180, in
 runTest
     raise self.failureException(self.format_failure(new.getvalue()))
 AssertionError: Failed doctest test for
 regressiontests.aggregation_regress.models.__test__.API_TESTS
   File
 "C:\u\kmt\django\trunk\tests\regressiontests\aggregation_regress\models.py",
 line unknown line number, in API_TESTS

 ----------------------------------------------------------------------
 File
 "C:\u\kmt\django\trunk\tests\regressiontests\aggregation_regress\models.py",
 line ?, in regressiontests.aggregation
 _regress.models.__test__.API_TESTS
 Failed example:
     sorted((k,v) for k,v in
 
Book.objects.all().annotate(mean_auth_age=Avg('authors__age')).extra(select={'manufacture_co
 st' : 'price * .5'}).get(pk=2).__dict__.items() if k != '_state')
 Exception raised:
     Traceback (most recent call last):
       File "C:\u\kmt\django\trunk\django\test\_doctest.py", line 1267, in
 __run
         compileflags, 1) in test.globs
       File "<doctest
 regressiontests.aggregation_regress.models.__test__.API_TESTS[9]>", line
 1, in <module>
         sorted((k,v) for k,v in
 
Book.objects.all().annotate(mean_auth_age=Avg('authors__age')).extra(select={'manufacture_cost'
 : 'price * .5'}).get(pk=2).__dict__.items() if k != '_state')
       File "C:\u\kmt\django\trunk\django\db\models\query.py", line 334, in
 get
         num = len(clone)
       File "C:\u\kmt\django\trunk\django\db\models\query.py", line 79, in
 __len__
         self._result_cache = list(self.iterator())
       File "C:\u\kmt\django\trunk\django\db\models\query.py", line 267, in
 iterator
         for row in compiler.results_iter():
       File "C:\u\kmt\django\trunk\django\db\models\sql\compiler.py", line
 673, in results_iter
         for rows in self.execute_sql(MULTI):
       File "C:\u\kmt\django\trunk\django\db\models\sql\compiler.py", line
 728, in execute_sql
         cursor.execute(sql, params)
       File "C:\u\kmt\django\trunk\django\db\backends\oracle\base.py", line
 485, in execute
         return self.cursor.execute(query, self._param_generator(params))
     DatabaseError: ORA-00904: "MANUFACTURE_COST": invalid identifier

 ----------------------------------------------------------------------
 File
 "C:\u\kmt\django\trunk\tests\regressiontests\aggregation_regress\models.py",
 line ?, in regressiontests.aggregation
 _regress.models.__test__.API_TESTS
 Failed example:
     sorted((k,v) for k,v in
 Book.objects.all().extra(select={'manufacture_cost' : 'price *
 .5'}).annotate(mean_auth_age=
 Avg('authors__age')).get(pk=2).__dict__.items()if k != '_state')
 Exception raised:
     Traceback (most recent call last):
       File "C:\u\kmt\django\trunk\django\test\_doctest.py", line 1267, in
 __run
         compileflags, 1) in test.globs
       File "<doctest
 regressiontests.aggregation_regress.models.__test__.API_TESTS[10]>", line
 1, in <module>
         sorted((k,v) for k,v in
 Book.objects.all().extra(select={'manufacture_cost' : 'price *
 .5'}).annotate(mean_auth_age=Avg('authors__age')).get(pk=2).__dict__.items()if
 k != '_state')
       File "C:\u\kmt\django\trunk\django\db\models\query.py", line 334, in
 get
         num = len(clone)
       File "C:\u\kmt\django\trunk\django\db\models\query.py", line 79, in
 __len__
         self._result_cache = list(self.iterator())
       File "C:\u\kmt\django\trunk\django\db\models\query.py", line 267, in
 iterator
         for row in compiler.results_iter():
       File "C:\u\kmt\django\trunk\django\db\models\sql\compiler.py", line
 673, in results_iter
         for rows in self.execute_sql(MULTI):
       File "C:\u\kmt\django\trunk\django\db\models\sql\compiler.py", line
 728, in execute_sql
         cursor.execute(sql, params)
       File "C:\u\kmt\django\trunk\django\db\backends\oracle\base.py", line
 485, in execute
         return self.cursor.execute(query, self._param_generator(params))
     DatabaseError: ORA-00904: "MANUFACTURE_COST": invalid identifier

 ----------------------------------------------------------------------
 File
 "C:\u\kmt\django\trunk\tests\regressiontests\aggregation_regress\models.py",
 line ?, in regressiontests.aggregation
 _regress.models.__test__.API_TESTS
 Failed example:
     sorted((k,v) for k,v in
 
Book.objects.all().annotate(mean_auth_age=Avg('authors__age')).extra(select={'manufacture_cost'
 : 'price * .5'}).values().get(pk=2).items()if k != '_state')
 Exception raised:
     Traceback (most recent call last):
       File "C:\u\kmt\django\trunk\django\test\_doctest.py", line 1267, in
 __run
         compileflags, 1) in test.globs
       File "<doctest
 regressiontests.aggregation_regress.models.__test__.API_TESTS[11]>", line
 1, in <module>
         sorted((k,v) for k,v in
 
Book.objects.all().annotate(mean_auth_age=Avg('authors__age')).extra(select={'manufacture_cost'
 : 'price * .5'}).values().get(pk=2).items()if k != '_state')
       File "C:\u\kmt\django\trunk\django\db\models\query.py", line 334, in
 get
         num = len(clone)
       File "C:\u\kmt\django\trunk\django\db\models\query.py", line 79, in
 __len__
         self._result_cache = list(self.iterator())
       File "C:\u\kmt\django\trunk\django\db\models\query.py", line 824, in
 iterator
         for row in self.query.get_compiler(self.db).results_iter():
       File "C:\u\kmt\django\trunk\django\db\models\sql\compiler.py", line
 673, in results_iter
         for rows in self.execute_sql(MULTI):
       File "C:\u\kmt\django\trunk\django\db\models\sql\compiler.py", line
 728, in execute_sql
         cursor.execute(sql, params)
       File "C:\u\kmt\django\trunk\django\db\backends\oracle\base.py", line
 485, in execute
         return self.cursor.execute(query, self._param_generator(params))
     DatabaseError: ORA-00904: "MANUFACTURE_COST": invalid identifier

 ----------------------------------------------------------------------
 File
 "C:\u\kmt\django\trunk\tests\regressiontests\aggregation_regress\models.py",
 line ?, in regressiontests.aggregation
 _regress.models.__test__.API_TESTS
 Failed example:
     sorted((k,v) for k,v in
 
Book.objects.all().values().annotate(mean_auth_age=Avg('authors__age')).extra(select={'manufacture_cost'
 : 'price * .5'}).get(pk=2).items()if k != '_state')
 Exception raised:
     Traceback (most recent call last):
       File "C:\u\kmt\django\trunk\django\test\_doctest.py", line 1267, in
 __run
         compileflags, 1) in test.globs
       File "<doctest
 regressiontests.aggregation_regress.models.__test__.API_TESTS[12]>", line
 1, in <module>
         sorted((k,v) for k,v in
 
Book.objects.all().values().annotate(mean_auth_age=Avg('authors__age')).extra(select={'m
 anufacture_cost' : 'price * .5'}).get(pk=2).items()if k != '_state')
       File "C:\u\kmt\django\trunk\django\db\models\query.py", line 334, in
 get
         num = len(clone)
       File "C:\u\kmt\django\trunk\django\db\models\query.py", line 79, in
 __len__
         self._result_cache = list(self.iterator())
       File "C:\u\kmt\django\trunk\django\db\models\query.py", line 824, in
 iterator
         for row in self.query.get_compiler(self.db).results_iter():
       File "C:\u\kmt\django\trunk\django\db\models\sql\compiler.py", line
 673, in results_iter
         for rows in self.execute_sql(MULTI):
       File "C:\u\kmt\django\trunk\django\db\models\sql\compiler.py", line
 728, in execute_sql
         cursor.execute(sql, params)
       File "C:\u\kmt\django\trunk\django\db\backends\oracle\base.py", line
 485, in execute
         return self.cursor.execute(query, self._param_generator(params))
     DatabaseError: ORA-00904: "MANUFACTURE_COST": invalid identifier

 ----------------------------------------------------------------------
 File
 "C:\u\kmt\django\trunk\tests\regressiontests\aggregation_regress\models.py",
 line ?, in regressiontests.aggregation
 _regress.models.__test__.API_TESTS
 Failed example:
 
Book.objects.extra(select={'pub':'publisher_id'}).values('pub').annotate(Count('id')).order_by('pub')
 Exception raised:
     Traceback (most recent call last):
       File "C:\u\kmt\django\trunk\django\test\_doctest.py", line 1267, in
 __run
         compileflags, 1) in test.globs
       File "<doctest
 regressiontests.aggregation_regress.models.__test__.API_TESTS[45]>", line
 1, in <module>
 
Book.objects.extra(select={'pub':'publisher_id'}).values('pub').annotate(Count('id')).order_by('pub')
       File "C:\u\kmt\django\trunk\django\db\models\query.py", line 66, in
 __repr__
         data = list(self[:REPR_OUTPUT_SIZE + 1])
       File "C:\u\kmt\django\trunk\django\db\models\query.py", line 81, in
 __len__
         self._result_cache.extend(list(self._iter))
       File "C:\u\kmt\django\trunk\django\db\models\query.py", line 824, in
 iterator
         for row in self.query.get_compiler(self.db).results_iter():
       File "C:\u\kmt\django\trunk\django\db\models\sql\compiler.py", line
 673, in results_iter
         for rows in self.execute_sql(MULTI):
       File "C:\u\kmt\django\trunk\django\db\models\sql\compiler.py", line
 728, in execute_sql
         cursor.execute(sql, params)
       File "C:\u\kmt\django\trunk\django\db\backends\oracle\base.py", line
 485, in execute
         return self.cursor.execute(query, self._param_generator(params))
     DatabaseError: ORA-00904: "PUB": invalid identifier

 ----------------------------------------------------------------------
 File
 "C:\u\kmt\django\trunk\tests\regressiontests\aggregation_regress\models.py",
 line ?, in regressiontests.aggregation
 _regress.models.__test__.API_TESTS
 Failed example:
 
Book.objects.extra(select={'pub':'publisher_id','foo':'pages'}).values('pub').annotate(Count('id')).order_by('pub')
 Exception raised:
     Traceback (most recent call last):
       File "C:\u\kmt\django\trunk\django\test\_doctest.py", line 1267, in
 __run
         compileflags, 1) in test.globs
       File "<doctest
 regressiontests.aggregation_regress.models.__test__.API_TESTS[46]>", line
 1, in <module>
 
Book.objects.extra(select={'pub':'publisher_id','foo':'pages'}).values('pub').annotate(Count('id')).order_by('pu
 b')
       File "C:\u\kmt\django\trunk\django\db\models\query.py", line 66, in
 __repr__
         data = list(self[:REPR_OUTPUT_SIZE + 1])
       File "C:\u\kmt\django\trunk\django\db\models\query.py", line 81, in
 __len__
         self._result_cache.extend(list(self._iter))
       File "C:\u\kmt\django\trunk\django\db\models\query.py", line 824, in
 iterator
         for row in self.query.get_compiler(self.db).results_iter():
       File "C:\u\kmt\django\trunk\django\db\models\sql\compiler.py", line
 673, in results_iter
         for rows in self.execute_sql(MULTI):
       File "C:\u\kmt\django\trunk\django\db\models\sql\compiler.py", line
 728, in execute_sql
         cursor.execute(sql, params)
       File "C:\u\kmt\django\trunk\django\db\backends\oracle\base.py", line
 485, in execute
         return self.cursor.execute(query, self._param_generator(params))
     DatabaseError: ORA-00904: "PUB": invalid identifier

 ----------------------------------------------------------------------
 File
 "C:\u\kmt\django\trunk\tests\regressiontests\aggregation_regress\models.py",
 line ?, in regressiontests.aggregation
 _regress.models.__test__.API_TESTS
 Failed example:
     [int(x['sheets']) for x in qs]
 Exception raised:
     Traceback (most recent call last):
       File "C:\u\kmt\django\trunk\django\test\_doctest.py", line 1267, in
 __run
         compileflags, 1) in test.globs
       File "<doctest
 regressiontests.aggregation_regress.models.__test__.API_TESTS[61]>", line
 1, in <module>
         [int(x['sheets']) for x in qs]
       File "C:\u\kmt\django\trunk\django\db\models\query.py", line 104, in
 _result_iter
         self._fill_cache()
       File "C:\u\kmt\django\trunk\django\db\models\query.py", line 755, in
 _fill_cache
         self._result_cache.append(self._iter.next())
       File "C:\u\kmt\django\trunk\django\db\models\query.py", line 824, in
 iterator
         for row in self.query.get_compiler(self.db).results_iter():
       File "C:\u\kmt\django\trunk\django\db\models\sql\compiler.py", line
 673, in results_iter
         for rows in self.execute_sql(MULTI):
       File "C:\u\kmt\django\trunk\django\db\models\sql\compiler.py", line
 728, in execute_sql
         cursor.execute(sql, params)
       File "C:\u\kmt\django\trunk\django\db\backends\oracle\base.py", line
 485, in execute
         return self.cursor.execute(query, self._param_generator(params))
     DatabaseError: ORA-00904: "SHEETS": invalid identifier



 ----------------------------------------------------------------------
 Ran 2 tests in 3.953s

 FAILED (failures=1, errors=1)

 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/11916#comment:10>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to