Commits

Michael Manfre committed 2fe366a

Fixed ``cast_avg_to_float`` so that it only controls the cast for ``AVG`` and not mapping other aggregates.

Comments (0)

Files changed (2)

docs/changelog.txt

 - Apply fix for :djangoticket:`12192`. If QuerySet slicing would result in ``LIMIT 0``, then it shouldn't reach
   the database because there will be no response.
 - Implemented DatabaseOperation ``cache_key_culling_sql``. :djangoticket:`18330`
+- Fixed ``cast_avg_to_float`` so that it only controls the cast for ``AVG`` and not mapping other aggregates.
 
 v1.2
 ----

sqlserver_ado/compiler.py

         match behavior of other django backends, it needs to not drop remainders.
         E.g. AVG([1, 2]) needs to yield 1.5, not 1
         """
-        if self.connection.cast_avg_to_float:
-            for alias, aggregate in self.query.aggregate_select.items():
-                if aggregate.sql_function == 'AVG':
-                    # Embed the CAST in the template on this query to
-                    # maintain multi-db support.
-                    self.query.aggregate_select[alias].sql_template = \
-                        '%(function)s(CAST(%(field)s AS FLOAT))'
-                # translate StdDev function names
-                elif aggregate.sql_function == 'STDDEV_SAMP':
-                    self.query.aggregate_select[alias].sql_function = 'STDEV'
-                elif aggregate.sql_function == 'STDDEV_POP':
-                    self.query.aggregate_select[alias].sql_function = 'STDEVP'
-                # translate Variance function names
-                elif aggregate.sql_function == 'VAR_SAMP':
-                    self.query.aggregate_select[alias].sql_function = 'VAR'
-                elif aggregate.sql_function == 'VAR_POP':
-                    self.query.aggregate_select[alias].sql_function = 'VARP'
+        for alias, aggregate in self.query.aggregate_select.items():
+            if aggregate.sql_function == 'AVG' and self.connection.cast_avg_to_float:
+                # Embed the CAST in the template on this query to
+                # maintain multi-db support.
+                self.query.aggregate_select[alias].sql_template = \
+                    '%(function)s(CAST(%(field)s AS FLOAT))'
+            # translate StdDev function names
+            elif aggregate.sql_function == 'STDDEV_SAMP':
+                self.query.aggregate_select[alias].sql_function = 'STDEV'
+            elif aggregate.sql_function == 'STDDEV_POP':
+                self.query.aggregate_select[alias].sql_function = 'STDEVP'
+            # translate Variance function names
+            elif aggregate.sql_function == 'VAR_SAMP':
+                self.query.aggregate_select[alias].sql_function = 'VAR'
+            elif aggregate.sql_function == 'VAR_POP':
+                self.query.aggregate_select[alias].sql_function = 'VARP'
 
     def as_sql(self, with_limits=True, with_col_aliases=False):
         # Django #12192 - Don't execute any DB query when QS slicing results in limit 0
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.