Skip to content

Commit d329a1b

Browse files
authored
Work around test flake casued by asyncpg bug (#8160)
The asyncpg client-side understanding of client_encoding was getting out of sync, causing encoding errors. See MagicStack/asyncpg#1215. This shows up when test_sql_query_client_encoding_2 and test_sql_query_client_encoding_3 are run on the same connection, so could be deterministically produced with `edb test -v -j 1 -k test_sql_query_client_encoding`
1 parent 73c212a commit d329a1b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

tests/test_sql_query.py

+16
Original file line numberDiff line numberDiff line change
@@ -1619,6 +1619,22 @@ async def test_sql_query_client_encoding_2(self):
16191619
with self.assertRaises(asyncpg.UntranslatableCharacterError):
16201620
await self.squery_values('select * from "Genre"')
16211621

1622+
# Bug workaround: because of MagicStack/asyncpg#1215, if an
1623+
# error occurs inside a transaction where a config was set,
1624+
# when the transaction is rolled back the client-side version
1625+
# of that config is not reverted. This was causing other tests
1626+
# to fail with encoding errors.
1627+
# Get things back into a good state.
1628+
await self.stran.rollback()
1629+
self.stran = self.scon.transaction()
1630+
await self.stran.start()
1631+
# ... need to change it away then change it back to have it show up
1632+
await self.squery_values("set client_encoding to 'latin1'")
1633+
await self.squery_values("set client_encoding to 'UTF8'")
1634+
self.assertEqual(
1635+
self.scon.get_settings().client_encoding.lower(), "utf8"
1636+
)
1637+
16221638
async def test_sql_query_client_encoding_3(self):
16231639
non_english = "奇奇怪怪"
16241640
rv1 = await self.squery_values('select $1::text', non_english)

0 commit comments

Comments
 (0)