mirror of
https://github.com/netbox-community/netbox.git
synced 2026-03-29 22:02:11 +02:00
Fix new annotation semantics (with backward-compatibility)
This commit is contained in:
@@ -677,15 +677,19 @@ class ConfigContextTest(TestCase):
|
|||||||
if hasattr(node, 'children'):
|
if hasattr(node, 'children'):
|
||||||
for child in node.children:
|
for child in node.children:
|
||||||
try:
|
try:
|
||||||
if child.rhs.query.model is TaggedItem:
|
# In Django 6.0+, rhs is a Query directly; older Django wraps it in Subquery
|
||||||
subqueries.append(child.rhs.query)
|
rhs_query = getattr(child.rhs, 'query', child.rhs)
|
||||||
|
if rhs_query.model is TaggedItem:
|
||||||
|
subqueries.append(rhs_query)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
traverse(child)
|
traverse(child)
|
||||||
traverse(where_node)
|
traverse(where_node)
|
||||||
return subqueries
|
return subqueries
|
||||||
|
|
||||||
|
# In Django 6.0+, the annotation is a Query directly; older Django wraps it in Subquery
|
||||||
|
annotation_query = getattr(config_annotation, 'query', config_annotation)
|
||||||
# Find subqueries in the WHERE clause that should have DISTINCT
|
# Find subqueries in the WHERE clause that should have DISTINCT
|
||||||
tag_subqueries = find_tag_subqueries(config_annotation.query.where)
|
tag_subqueries = find_tag_subqueries(annotation_query.where)
|
||||||
distinct_subqueries = [sq for sq in tag_subqueries if sq.distinct]
|
distinct_subqueries = [sq for sq in tag_subqueries if sq.distinct]
|
||||||
|
|
||||||
# Verify we found at least one DISTINCT subquery for tags
|
# Verify we found at least one DISTINCT subquery for tags
|
||||||
|
|||||||
Reference in New Issue
Block a user