From ed20e2f95f52a072d0c6b09af095b4cda0436d38 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 11 Dec 2020 19:01:12 -0500 Subject: 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 --- test/sql/test_utils.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'test/sql/test_utils.py') 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 = [] -- cgit v1.2.1