]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
Add public accessor to for `is_single_entity` to Query class
authorPatrick Hayes <pfhayes@gmail.com>
Tue, 22 Oct 2019 16:47:52 +0000 (09:47 -0700)
committerPatrick Hayes <pfhayes@gmail.com>
Tue, 22 Oct 2019 16:59:34 +0000 (09:59 -0700)
commitf6fd726cdb91a0b1c5eb132936a1099ec1ce87fc
tree8ecba9d776db6a2fef177b4f18162388127c6c81
parentd76cb7213557c24609a1a75d8c391aea0179562a
Add public accessor to for `is_single_entity` to Query class

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
lib/sqlalchemy/orm/loading.py
lib/sqlalchemy/orm/query.py