Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit becf996

Browse files
zzzeekGerrit Code Review
authored andcommitted
Merge "Restore Query.selectable"
2 parents 2d8dca0 + b139451 commit becf996

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.. change::
2+
:tags: bug, regression, orm
3+
:tickets: 6088
4+
5+
Fixed regression where the :attr:`_orm.Query.selectable` accessor, which is
6+
a synonym for :meth:`_orm.Query.__clause_element__`, got removed, it's now
7+
restored.

lib/sqlalchemy/orm/query.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,18 @@ def scalar_subquery(self):
595595

596596
return self.enable_eagerloads(False).statement.scalar_subquery()
597597

598+
@property
599+
def selectable(self):
600+
"""Return the :class:`_expression.Select` object emitted by this
601+
:class:`_query.Query`.
602+
603+
Used for :func:`_sa.inspect` compatibility, this is equivalent to::
604+
605+
query.enable_eagerloads(False).with_labels().statement
606+
607+
"""
608+
return self.__clause_element__()
609+
598610
def __clause_element__(self):
599611
return (
600612
self.enable_eagerloads(False)

test/orm/test_query.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,35 @@ def test_with_session(self):
104104
assert q2.session is s2
105105
assert q1.session is s1
106106

107+
@testing.combinations(
108+
(lambda s, User: s.query(User)),
109+
(lambda s, User: s.query(User).filter_by(name="x")),
110+
(lambda s, User: s.query(User.id, User.name).filter_by(name="x")),
111+
(
112+
lambda s, User: s.query(func.count(User.id)).filter(
113+
User.name == "x"
114+
)
115+
),
116+
)
117+
def test_rudimentary_statement_accessors(self, test_case):
118+
User = self.classes.User
119+
120+
s = fixture_session()
121+
122+
q1 = testing.resolve_lambda(test_case, s=s, User=User)
123+
124+
is_true(
125+
q1.statement.set_label_style(
126+
LABEL_STYLE_TABLENAME_PLUS_COL
127+
).compare(q1.__clause_element__())
128+
)
129+
130+
is_true(
131+
q1.statement.set_label_style(
132+
LABEL_STYLE_TABLENAME_PLUS_COL
133+
).compare(q1.selectable)
134+
)
135+
107136

108137
class OnlyReturnTuplesTest(QueryTest):
109138
def test_single_entity_false(self):

0 commit comments

Comments
 (0)