diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2023-03-19 10:37:15 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2023-03-19 13:33:23 -0400 |
| commit | fa0666cb04174cdd2592ab1327d48e431fe86ffa (patch) | |
| tree | 020edb674c435b2b3a3ba4e3a4fbdb4556ab93a2 /lib/sqlalchemy/testing | |
| parent | b56494ba64f858a60a3314fd549ced4512a5fe19 (diff) | |
| download | sqlalchemy-fa0666cb04174cdd2592ab1327d48e431fe86ffa.tar.gz | |
dont render VARCHAR length for PG casts
Fixed critical regression in PostgreSQL dialects such as asyncpg which rely
upon explicit casts in SQL in order for datatypes to be passed to the
driver correctly, where a :class:`.String` datatype would be cast along
with the exact column length being compared, leading to implicit truncation
when comparing a ``VARCHAR`` of a smaller length to a string of greater
length regardless of operator in use (e.g. LIKE, MATCH, etc.). The
PostgreSQL dialect now omits the length from ``VARCHAR`` when rendering
these casts.
Fixes: #9511
Change-Id: If094146d8cfd989a0b780872f38e86fd41ebfec2
Diffstat (limited to 'lib/sqlalchemy/testing')
| -rw-r--r-- | lib/sqlalchemy/testing/suite/test_types.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/sqlalchemy/testing/suite/test_types.py b/lib/sqlalchemy/testing/suite/test_types.py index bc2885341..44d174086 100644 --- a/lib/sqlalchemy/testing/suite/test_types.py +++ b/lib/sqlalchemy/testing/suite/test_types.py @@ -397,6 +397,25 @@ class StringTest(_LiteralRoundTripFixture, fixtures.TestBase): def test_literal_non_ascii(self, literal_round_trip): literal_round_trip(String(40), ["réve🐍 illé"], ["réve🐍 illé"]) + @testing.combinations( + ("%B%", ["AB", "BC"]), + ("A%C", ["AC"]), + ("A%C%Z", []), + argnames="expr, expected", + ) + def test_dont_truncate_rightside( + self, metadata, connection, expr, expected + ): + t = Table("t", metadata, Column("x", String(2))) + t.create(connection) + + connection.execute(t.insert(), [{"x": "AB"}, {"x": "BC"}, {"x": "AC"}]) + + eq_( + connection.scalars(select(t.c.x).where(t.c.x.like(expr))).all(), + expected, + ) + def test_literal_quoting(self, literal_round_trip): data = """some 'text' hey "hi there" that's text""" literal_round_trip(String(40), [data], [data]) |
