diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-03-23 10:07:13 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2022-03-23 10:26:54 -0400 |
| commit | 58fad097209e37d727988d03a60367b6e7dbc917 (patch) | |
| tree | 8dc237d81fbb3b539497f839a1e12b3744eb74fd /test/sql | |
| parent | 845aacd5fc8fdc7839597c0e75c447180f7b438d (diff) | |
| download | sqlalchemy-58fad097209e37d727988d03a60367b6e7dbc917.tar.gz | |
Add option to disable from linting for table valued function
Added new parameter
:paramref:`.FunctionElement.table_valued.joins_implicitly`, for the
:meth:`.FunctionElement.table_valued` construct. This parameter indicates
that the given table-valued function implicitly joins to the table it
refers towards, essentially disabling the "from linting" feature, i.e. the
"cartesian product" warning, from taking effect due to the presence of this
parameter. May be used for functions such as ``func.json_each()``.
Fixes: #7845
Change-Id: I80edcb74efbd4417172132c0db4d9c756fdd5eae
(cherry picked from commit 04dcc5c704dbf0b22705523e263e512c24936175)
Diffstat (limited to 'test/sql')
| -rw-r--r-- | test/sql/test_from_linter.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/sql/test_from_linter.py b/test/sql/test_from_linter.py index a22913868..4a4d907f9 100644 --- a/test/sql/test_from_linter.py +++ b/test/sql/test_from_linter.py @@ -1,6 +1,10 @@ +from sqlalchemy import column +from sqlalchemy import func from sqlalchemy import Integer +from sqlalchemy import JSON from sqlalchemy import select from sqlalchemy import sql +from sqlalchemy import table from sqlalchemy import testing from sqlalchemy import true from sqlalchemy.testing import config @@ -161,6 +165,30 @@ class TestFindUnmatchingFroms(fixtures.TablesTest): assert start is p3 assert froms == {p1} + @testing.combinations(True, False, argnames="joins_implicitly") + def test_table_valued(self, joins_implicitly): + """test #7845""" + my_table = table( + "tbl", + column("id", Integer), + column("data", JSON()), + ) + + sub_dict = my_table.c.data["d"] + tv = func.json_each(sub_dict).table_valued( + "key", joins_implicitly=joins_implicitly + ) + has_key = tv.c.key == "f" + stmt = select(my_table.c.id).where(has_key) + froms, start = find_unmatching_froms(stmt, my_table) + + if joins_implicitly: + is_(start, None) + is_(froms, None) + else: + assert start == my_table + assert froms == {tv} + def test_count_non_eq_comparison_operators(self): query = select(self.a).where(self.a.c.col_a > self.b.c.col_b) froms, start = find_unmatching_froms(query, self.a) |
