summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2009-10-15 19:08:35 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2009-10-15 19:08:35 +0000
commitcf6c66e70ea406a27c4a8d5b79f9c629a62320fc (patch)
tree3db2c7aeaf4947bfd540396a8e92264a835f72e5
parentc5571ab19a155f0c11381d65edc07c16902f3fad (diff)
downloadsqlalchemy-cf6c66e70ea406a27c4a8d5b79f9c629a62320fc.tar.gz
- 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]
-rw-r--r--CHANGES4
-rw-r--r--lib/sqlalchemy/orm/mapper.py9
-rw-r--r--test/orm/test_mapper.py5
-rw-r--r--test/orm/test_selectable.py10
4 files changed, 16 insertions, 12 deletions
diff --git a/CHANGES b/CHANGES
index e02f56954..e67373262 100644
--- 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])
diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py
index 13151f232..a9dad9176 100644
--- a/lib/sqlalchemy/orm/mapper.py
+++ b/lib/sqlalchemy/orm/mapper.py
@@ -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())
diff --git a/test/orm/test_mapper.py b/test/orm/test_mapper.py
index 79286fe2a..321ac25c1 100644
--- a/test/orm/test_mapper.py
+++ b/test/orm/test_mapper.py
@@ -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
diff --git a/test/orm/test_selectable.py b/test/orm/test_selectable.py
index bfa400895..e46d8bbc8 100644
--- a/test/orm/test_selectable.py
+++ b/test/orm/test_selectable.py
@@ -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)