diff --git a/tests/testapp/test_queries.py b/tests/testapp/test_queries.py index f021547..6f4d875 100644 --- a/tests/testapp/test_queries.py +++ b/tests/testapp/test_queries.py @@ -149,6 +149,26 @@ def test_update_aggregate(self): ) def test_values(self): + tree = self.create_tree() + self.assertEqual( + list(Model.objects.ancestors(tree.child2_1).values()), + [ + { + "custom_id": tree.root.pk, + "name": "root", + "order": 0, + "parent_id": None, + }, + { + "custom_id": tree.child2.pk, + "name": "2", + "order": 1, + "parent_id": tree.root.pk, + }, + ], + ) + + def test_values_list(self): tree = self.create_tree() self.assertEqual( list( diff --git a/tree_queries/compiler.py b/tree_queries/compiler.py index 7ceef0c..37b6172 100644 --- a/tree_queries/compiler.py +++ b/tree_queries/compiler.py @@ -210,11 +210,13 @@ def as_sql(self, *args, **kwargs): # I am not confident that this is the perfect way to approach this # problem but I just gotta stop worrying and trust the testsuite. skip_tree_fields = ( - self.query.distinct and self.query.subquery - ) or any( # pragma: no branch - # OK if generator is not consumed completely - annotation.is_summary - for alias, annotation in self.query.annotations.items() + (self.query.distinct and self.query.subquery) + or self.query.values_select + or any( # pragma: no branch + # OK if generator is not consumed completely + annotation.is_summary + for alias, annotation in self.query.annotations.items() + ) ) opts = _find_tree_model(self.query.model)._meta