mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #28107 -- Added DatabaseFeatures.allows_group_by_selected_pks_on_model() to allow enabling optimization for unmanaged models.
This commit is contained in:
committed by
Mariusz Felisiak
parent
10d5e439e9
commit
b1d37fea8f
@@ -313,3 +313,8 @@ class BaseDatabaseFeatures:
|
||||
count, = cursor.fetchone()
|
||||
cursor.execute('DROP TABLE ROLLBACK_TEST')
|
||||
return count == 0
|
||||
|
||||
def allows_group_by_selected_pks_on_model(self, model):
|
||||
if not self.allows_group_by_selected_pks:
|
||||
return False
|
||||
return model._meta.managed
|
||||
|
||||
@@ -171,7 +171,11 @@ class SQLCompiler:
|
||||
# database views on which the optimization might not be allowed.
|
||||
pks = {
|
||||
expr for expr in expressions
|
||||
if hasattr(expr, 'target') and expr.target.primary_key and expr.target.model._meta.managed
|
||||
if (
|
||||
hasattr(expr, 'target') and
|
||||
expr.target.primary_key and
|
||||
self.connection.features.allows_group_by_selected_pks_on_model(expr.target.model)
|
||||
)
|
||||
}
|
||||
aliases = {expr.alias for expr in pks}
|
||||
expressions = [
|
||||
|
||||
Reference in New Issue
Block a user