]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- mapping to a select() construct now requires that you
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 15 Oct 2009 19:08:35 +0000 (19:08 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 15 Oct 2009 19:08:35 +0000 (19:08 +0000)
make an alias() out of it distinctly.   This to eliminate
confusion over such issues as [ticket:1542]

CHANGES
lib/sqlalchemy/orm/mapper.py
test/orm/test_mapper.py
test/orm/test_selectable.py

diff --git a/CHANGES b/CHANGES
index e02f56954d710f415f23652af53e33e8a4f0eabf..e67373262f65a7eed556cd4153267ce2d86f3f3e 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -31,6 +31,10 @@ CHANGES
 
   - the "named tuple" objects returned when iterating a
     Query() are now pickleable.
+
+  - mapping to a select() construct now requires that you 
+    make an alias() out of it distinctly.   This to eliminate
+    confusion over such issues as [ticket:1542]
     
   - query.join() has been reworked to provide more consistent 
     behavior and more flexibility (includes [ticket:1537])
index 13151f2321d850a18b84c521e34e26510b4335fc..a9dad91766df480c7b371135d278a5a4081bf51d 100644 (file)
@@ -163,11 +163,10 @@ class Mapper(object):
                 self.with_polymorphic = None
 
         if isinstance(self.local_table, expression._SelectBaseMixin):
-            util.warn("mapper %s creating an alias for the given "
-                        "selectable.  References to the original selectable "
-                        "may be misinterpreted by queries, polymorphic_on, etc. "
-                        " Consider passing an explicit selectable.alias() construct instead." % self)
-            self.local_table = self.local_table.alias()
+            raise sa_exc.InvalidRequestError(
+                "When mapping against a select() construct, map against an alias() of the construct instead."
+                "This because several databases don't allow a SELECT from a subquery that does not have an alias."
+                )
 
         if self.with_polymorphic and isinstance(self.with_polymorphic[1], expression._SelectBaseMixin):
             self.with_polymorphic = (self.with_polymorphic[0], self.with_polymorphic[1].alias())
index 79286fe2a9f72ab6dd1e3f25410298dd224d95e8..321ac25c1e76e41bfd085d44d429503d827d0c9c 100644 (file)
@@ -115,12 +115,9 @@ class MapperTest(_fixtures.FixtureTest):
         s = sa.select([users.c.name]).alias('foo')
         assert_raises(sa.exc.ArgumentError, mapper, User, s)
 
-    @testing.emits_warning(
-        'mapper Mapper|User|Select object creating an alias for '
-        'the given selectable - use Class attributes for queries')
     @testing.resolve_artifact_names
     def test_no_pks_2(self):
-        s = sa.select([users.c.name])
+        s = sa.select([users.c.name]).alias()
         assert_raises(sa.exc.ArgumentError, mapper, User, s)
 
     @testing.resolve_artifact_names
index bfa40089573e0f0418a0abc34f990f7140b167f4..e46d8bbc80d2d49f01f03e2b331ce0b5c32f01e8 100644 (file)
@@ -27,15 +27,19 @@ class SelectableNoFromsTest(_base.MappedTest):
     @testing.resolve_artifact_names
     def test_no_tables(self):
 
-        selectable = select(["x", "y", "z"])
+        selectable = select(["x", "y", "z"]).alias()
         assert_raises_message(sa.exc.InvalidRequestError,
                                  "Could not find any Table objects",
                                  mapper, Subset, selectable)
 
-    @testing.emits_warning('.*creating an Alias.*')
     @testing.resolve_artifact_names
-    def test_basic(self):
+    def test_no_selects(self):
         subset_select = select([common.c.id, common.c.data])
+        assert_raises(sa.exc.InvalidRequestError, mapper, Subset, subset_select)
+        
+    @testing.resolve_artifact_names
+    def test_basic(self):
+        subset_select = select([common.c.id, common.c.data]).alias()
         subset_mapper = mapper(Subset, subset_select)
 
         sess = create_session(bind=testing.db)