Fixes: #4934
This is useful when writing middleware between your application
and sqlalchemy, to inspect what type of results we will be seeing.
As an example,
```
def issue_query_and_wrap_results(query, Wrapper):
results = query.all()
for result in results:
if q.is_single_entity:
return Wrapper(result)
else:
return tuple(Wrapper(r) for r in result)
```
Without this accessor, you need to inspect the return results or private members of the
query and try to guess the intent
filtered = query._has_mapper_entities
- single_entity = (
- not query._only_return_tuples
- and len(query._entities) == 1
- and query._entities[0].supports_single_entity
- )
+ single_entity = query.is_single_entity
if filtered:
if single_entity:
"""
self._only_return_tuples = value
+ @property
+ def is_single_entity(self):
+ """Returns True if this query returns a single entity for each instance in its
+ result list, and False if this query returns a tuple of entities for each result.
+
+ """
+ return (
+ not self._only_return_tuples
+ and len(self._entities) == 1
+ and self._entities[0].supports_single_entity
+ )
+
@_generative
def enable_eagerloads(self, value):
"""Control whether or not eager joins and subqueries are