summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2021-03-19 12:23:48 +0000
committerGerrit Code Review <gerrit@ci3.zzzcomputing.com>2021-03-19 12:23:48 +0000
commit37ef5f38523329f3e881c4f70d38d5589510af9f (patch)
treea667d03848c6652ea2f461a567984b30b49fe71d /test
parentaabb899ea5adb437b7a9ee45edf2d492ae2a5980 (diff)
parente67d1b79c544c14f375dff90b5d8af5b472c053e (diff)
downloadsqlalchemy-37ef5f38523329f3e881c4f70d38d5589510af9f.tar.gz
Merge "Deannoate functions before matching .__class__"
Diffstat (limited to 'test')
-rw-r--r--test/orm/test_lazy_relations.py40
-rw-r--r--test/sql/test_functions.py7
2 files changed, 47 insertions, 0 deletions
diff --git a/test/orm/test_lazy_relations.py b/test/orm/test_lazy_relations.py
index 154e11952..1cbe10606 100644
--- a/test/orm/test_lazy_relations.py
+++ b/test/orm/test_lazy_relations.py
@@ -6,8 +6,10 @@ import sqlalchemy as sa
from sqlalchemy import and_
from sqlalchemy import bindparam
from sqlalchemy import Boolean
+from sqlalchemy import Date
from sqlalchemy import ForeignKey
from sqlalchemy import ForeignKeyConstraint
+from sqlalchemy import func
from sqlalchemy import Integer
from sqlalchemy import orm
from sqlalchemy import select
@@ -25,6 +27,7 @@ from sqlalchemy.orm import Session
from sqlalchemy.testing import assert_raises
from sqlalchemy.testing import eq_
from sqlalchemy.testing import fixtures
+from sqlalchemy.testing import is_
from sqlalchemy.testing import is_false
from sqlalchemy.testing import is_true
from sqlalchemy.testing.assertsql import CompiledSQL
@@ -761,6 +764,43 @@ class LazyTest(_fixtures.FixtureTest):
eq_(a1.user.id, 8)
+ @testing.only_on("sqlite")
+ def test_annotated_fn_criteria(self, registry, connection):
+ """this test is a secondary test for the compilation of functions
+ that are annotated.
+
+ """
+
+ @registry.mapped
+ class A(object):
+ __tablename__ = "a"
+
+ id = Column(Integer, primary_key=True)
+ _date = Column(Date, default=func.current_date())
+ b_id = Column(Integer, ForeignKey("b.id"))
+ b = relationship("B")
+
+ @registry.mapped
+ class B(object):
+ __tablename__ = "b"
+
+ id = Column(Integer, primary_key=True)
+ a_s = relationship(
+ "A",
+ primaryjoin="and_(B.id == A.b_id, "
+ "A._date >= func.current_date())",
+ viewonly=True,
+ )
+
+ registry.metadata.create_all(connection)
+ with Session(connection) as sess:
+ b1 = B(id=1)
+ a1 = A(b=b1)
+ sess.add_all([a1, b1])
+ sess.commit()
+
+ is_(sess.get(B, 1).a_s[0], a1)
+
def test_uses_get_compatible_types(self):
"""test the use_get optimization with compatible
but non-identical types"""
diff --git a/test/sql/test_functions.py b/test/sql/test_functions.py
index 96e0a9129..c5aca5d7f 100644
--- a/test/sql/test_functions.py
+++ b/test/sql/test_functions.py
@@ -256,6 +256,13 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
fn = func.coalesce("x", "y")._annotate({"foo": "bar"})
self.assert_compile(fn, "coalesce(:coalesce_1, :coalesce_2)")
+ def test_annotation_dialect_specific(self):
+ fn = func.current_date()
+ self.assert_compile(fn, "CURRENT_DATE", dialect="sqlite")
+
+ fn = fn._annotate({"foo": "bar"})
+ self.assert_compile(fn, "CURRENT_DATE", dialect="sqlite")
+
def test_custom_default_namespace(self):
class myfunc(GenericFunction):
pass