it also is implemented within merge() such that a SELECT
won't be issued for an incoming instance with partially
NULL primary key if the flag is False. [ticket:1680]
+
+ - Calling query.order_by() or query.distinct() before calling
+ query.select_from(), query.with_polymorphic(), or
+ query.from_statement() raises an exception now instead of
+ silently dropping those criterion. [ticket:1736]
- sql
- The most common result processors conversion function were
equivs.update(ent.mapper._equivalent_columns)
return equivs
+ def _get_condition(self):
+ self._order_by = self._distinct = False
+ return self._no_criterion_condition("get")
+
def _no_criterion_condition(self, meth):
if not self._enable_assertions:
return
if self._criterion is not None or self._statement is not None or self._from_obj or \
self._limit is not None or self._offset is not None or \
- self._group_by:
+ self._group_by or self._order_by or self._distinct:
raise sa_exc.InvalidRequestError(
"Query.%s() being called on a "
"Query with existing criterion. " % meth)
if refresh_state is None:
q = self._clone()
- q._no_criterion_condition("get")
+ q._get_condition()
else:
q = self._clone()
s = create_session()
q = s.query(User)
assert_raises(sa_exc.InvalidRequestError, q.add_column, object())
+
+ def test_distinct(self):
+ """test that a distinct() call is not valid before 'clauseelement' conditions."""
+
+ s = create_session()
+ q = s.query(User).distinct()
+ assert_raises(sa_exc.InvalidRequestError, q.select_from, User)
+ assert_raises(sa_exc.InvalidRequestError, q.from_statement, text("select * from table"))
+ assert_raises(sa_exc.InvalidRequestError, q.with_polymorphic, User)
+
+ def test_order_by(self):
+ """test that an order_by() call is not valid before 'clauseelement' conditions."""
+
+ s = create_session()
+ q = s.query(User).order_by(User.id)
+ assert_raises(sa_exc.InvalidRequestError, q.select_from, User)
+ assert_raises(sa_exc.InvalidRequestError, q.from_statement, text("select * from table"))
+ assert_raises(sa_exc.InvalidRequestError, q.with_polymorphic, User)
+
def test_mapper_zero(self):
s = create_session()