From 9bb80a8f11d73c8c30c5c44ef33b05ec2c8d2d20 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 31 Oct 2006 00:51:16 +0000 Subject: [PATCH] figured out how a Select can be in its own _froms list, changed assertion to just a continue --- lib/sqlalchemy/sql.py | 6 ++++-- test/sql/select.py | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/sqlalchemy/sql.py b/lib/sqlalchemy/sql.py index 61b3d277aa..ce33810a52 100644 --- a/lib/sqlalchemy/sql.py +++ b/lib/sqlalchemy/sql.py @@ -1455,6 +1455,7 @@ class Select(_SelectBaseMixin, FromClause): self._correlator = Select._CorrelatedVisitor(self, False) self._wherecorrelator = Select._CorrelatedVisitor(self, True) + self.group_by(*(group_by or [None])) self.order_by(*(order_by or [None])) @@ -1543,8 +1544,9 @@ class Select(_SelectBaseMixin, FromClause): def _locate_oid_column(self): for f in self._froms.values(): if f is self: - # TODO: why would we be in our own _froms list ? - raise exceptions.AssertionError("Select statement should not be in its own _froms list") + # we might be in our own _froms list if a column with us as the parent is attached, + # which includes textual columns. + continue oid = f.oid_column if oid is not None: return oid diff --git a/test/sql/select.py b/test/sql/select.py index 2804da3445..1c8927e6b1 100644 --- a/test/sql/select.py +++ b/test/sql/select.py @@ -314,6 +314,11 @@ WHERE mytable.myid = myothertable.otherid) AS t2view WHERE t2view.mytable_myid = s.append_from("table1") self.runtest(s, "SELECT column1, column2 FROM table1 WHERE column1=12 AND column2=19 ORDER BY column1") + def testtextcolumns(self): + self.runtest( + select(["column1", "column2"], from_obj=[table1]).alias('somealias').select(), + "SELECT somealias.column1, somealias.column2 FROM (SELECT column1, column2 FROM mytable) AS somealias" + ) def testtextbinds(self): self.runtest( text("select * from foo where lala=:bar and hoho=:whee"), -- 2.47.2