diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-12-11 19:01:12 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-12-11 22:01:57 -0500 |
commit | ed20e2f95f52a072d0c6b09af095b4cda0436d38 (patch) | |
tree | 340571f1d5bce61f5126a932a7739fee7efb3b77 /test/sql/test_utils.py | |
parent | 8e9e473dcb76b57a7f0eaa476481cb66a258ea69 (diff) | |
download | sqlalchemy-ed20e2f95f52a072d0c6b09af095b4cda0436d38.tar.gz |
Fixes for lambda expressions and relationship loaders
Fixed bug in lambda SQL feature, used by ORM
:meth:`_orm.with_loader_criteria` as well as available generally in the SQL
expression language, where assigning a boolean value True/False to a
variable would cause the query-time expression calculation to fail, as it
would produce a SQL expression not compatible with a bound value.
Fixed issue where the :attr:`_orm.ORMExecuteState.is_relationship_load`
parameter would not be set correctly for many lazy loads, all
selectinloads, etc. The flag is essential in order to test if options
should be added to statements or if they would already have been propagated
via relationship loads.
Fixes: #5763
Fixes: #5764
Change-Id: I66aafbef193f892ff75ede0670698647b7475482
Diffstat (limited to 'test/sql/test_utils.py')
-rw-r--r-- | test/sql/test_utils.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/sql/test_utils.py b/test/sql/test_utils.py index a4b76f35d..24a149ece 100644 --- a/test/sql/test_utils.py +++ b/test/sql/test_utils.py @@ -15,6 +15,7 @@ from sqlalchemy.sql import util as sql_util from sqlalchemy.testing import assert_raises from sqlalchemy.testing import assert_raises_message from sqlalchemy.testing import eq_ +from sqlalchemy.testing import expect_raises_message from sqlalchemy.testing import fixtures @@ -57,6 +58,34 @@ class MiscTest(fixtures.TestBase): {common, calias, subset_select}, ) + def test_incompatible_options_add_clslevel(self): + class opt1(sql_base.CacheableOptions): + _cache_key_traversal = [] + foo = "bar" + + with expect_raises_message( + TypeError, + "dictionary contains attributes not covered by " + "Options class .*opt1.* .*'bar'.*", + ): + o1 = opt1 + + o1 += {"foo": "f", "bar": "b"} + + def test_incompatible_options_add_instancelevel(self): + class opt1(sql_base.CacheableOptions): + _cache_key_traversal = [] + foo = "bar" + + o1 = opt1(foo="bat") + + with expect_raises_message( + TypeError, + "dictionary contains attributes not covered by " + "Options class .*opt1.* .*'bar'.*", + ): + o1 += {"foo": "f", "bar": "b"} + def test_options_merge(self): class opt1(sql_base.CacheableOptions): _cache_key_traversal = [] |