- 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])
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())
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
@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)