Commits

Michael Manfre committed b673ea1

Ensure _mssql_ordering_not_allowed is removed from the query.

Comments (0)

Files changed (1)

sqlserver_ado/compiler.py

 import datetime
 import re
 
-from contextlib import contextmanager
-
 # query_class returns the base class to use for Django queries.
 # The custom 'SqlServerQuery' class derives from django.db.models.sql.query.Query
 # which is passed in as "QueryClass" by Django itself.
 def _remove_order_limit_offset(sql):
     return _re_order_limit_offset.sub('',sql).split(None, 1)[1]
 
-@contextmanager
-def prevent_ordering_query(compiler_):
-    try:
-        setattr(query, '_mssql_ordering_not_allowed', True)
-        yield
-    finally:
-        delattr(query, '_mssql_ordering_not_allowed')
-
 class SQLCompiler(compiler.SQLCompiler):
     def resolve_columns(self, row, fields=()):
         # If the results are sliced, the resultset will have an initial 
             # The ORDER BY clause is invalid in views, inline functions, 
             # derived tables, subqueries, and common table expressions, 
             # unless TOP or FOR XML is also specified.
-            self.query._mssql_ordering_not_allowed = with_col_aliases
-            result = super(SQLCompiler, self).as_sql(with_limits, with_col_aliases)
-            # remove in case query is every reused
-            delattr(self.query, '_mssql_ordering_not_allowed')            
+            try:
+                setattr(self.query, '_mssql_ordering_not_allowed', with_col_aliases)
+                result = super(SQLCompiler, self).as_sql(with_limits, with_col_aliases)
+            finally:
+                # remove in case query is every reused
+                delattr(self.query, '_mssql_ordering_not_allowed')
             return result
 
         raw_sql, fields = super(SQLCompiler, self).as_sql(False, with_col_aliases)
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.