summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2015-06-11 16:48:00 -0400
committerStefan Urbanek <stefan@agentfarms.net>2015-08-25 23:55:57 -0700
commit40ec2efd36c238fa30c906dc0a60430fe39cee14 (patch)
treef73db2a9fa87eeab8d322450d3657bcc6c4b950b /test
parent93098513dffe2a2b1a781166d6bc18b5330200fc (diff)
downloadsqlalchemy-40ec2efd36c238fa30c906dc0a60430fe39cee14.tar.gz
- Fixed an unexpected-use regression whereby custom :class:`.Comparator`
objects that made use of the ``__clause_element__()`` method and returned an object that was an ORM-mapped :class:`.InstrumentedAttribute` and not explicitly a :class:`.ColumnElement` would fail to be correctly handled when passed as an expression to :meth:`.Session.query`. The logic in 0.9 happened to succeed on this, so this use case is now supported. fixes #3448
Diffstat (limited to 'test')
-rw-r--r--test/ext/test_hybrid.py1
-rw-r--r--test/orm/test_descriptor.py1
-rw-r--r--test/orm/test_query.py19
3 files changed, 21 insertions, 0 deletions
diff --git a/test/ext/test_hybrid.py b/test/ext/test_hybrid.py
index b895d2fb2..e36b8f7e9 100644
--- a/test/ext/test_hybrid.py
+++ b/test/ext/test_hybrid.py
@@ -7,6 +7,7 @@ from sqlalchemy.testing import eq_, AssertsCompiledSQL, assert_raises_message
from sqlalchemy.testing import fixtures
from sqlalchemy import inspect
+
class PropertyComparatorTest(fixtures.TestBase, AssertsCompiledSQL):
__dialect__ = 'default'
diff --git a/test/orm/test_descriptor.py b/test/orm/test_descriptor.py
index 2134d87b2..d9aca30e5 100644
--- a/test/orm/test_descriptor.py
+++ b/test/orm/test_descriptor.py
@@ -125,3 +125,4 @@ class DescriptorInstrumentationTest(fixtures.ORMTest):
str(aliased(Foo).foo == 'ed'),
"foobar(foo_1.name) = foobar(:foobar_1)"
)
+
diff --git a/test/orm/test_query.py b/test/orm/test_query.py
index 6a1eb57b4..41c0e2a21 100644
--- a/test/orm/test_query.py
+++ b/test/orm/test_query.py
@@ -1718,6 +1718,25 @@ class ColumnPropertyTest(_fixtures.FixtureTest, AssertsCompiledSQL):
)
+class ComparatorTest(QueryTest):
+ def test_clause_element_query_resolve(self):
+ from sqlalchemy.orm.properties import ColumnProperty
+ User = self.classes.User
+
+ class Comparator(ColumnProperty.Comparator):
+ def __init__(self, expr):
+ self.expr = expr
+
+ def __clause_element__(self):
+ return self.expr
+
+ sess = Session()
+ eq_(
+ sess.query(Comparator(User.id)).order_by(Comparator(User.id)).all(),
+ [(7, ), (8, ), (9, ), (10, )]
+ )
+
+
# more slice tests are available in test/orm/generative.py
class SliceTest(QueryTest):
def test_first(self):