Skip to content

Commit d338087

Browse files
committed
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 b43140f commit d338087

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

tests/test_sql_query.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,6 +1618,22 @@ async def test_sql_query_client_encoding_2(self):
16181618
with self.assertRaises(asyncpg.UntranslatableCharacterError):
16191619
await self.squery_values('select * from "Genre"')
16201620

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

0 commit comments

Comments
 (0)