@@ -1193,6 +1193,8 @@ def setUpClass(cls):
11931193 def setUp (self ):
11941194 super (PreparedStatementTestCase , self ).setUp ()
11951195 self ._table = 'preparedstmt_test'
1196+ self ._user = 'test_user'
1197+ self ._password = 'TestPassword123'
11961198 with self ._connect () as conn :
11971199 cur = conn .cursor ()
11981200 cur .execute ("DROP TABLE IF EXISTS {0}" .format (self ._table ))
@@ -1472,3 +1474,27 @@ def test_bind_udtype(self):
14721474
14731475 self .assertEqual (cur .description [0 ].display_size , 10000 )
14741476 self .assertEqual (cur .description [1 ].display_size , 1000 )
1477+
1478+ def test_multiple_permission_error (self ):
1479+ with self ._connect () as conn :
1480+ try :
1481+ cur = conn .cursor ()
1482+ cur .execute ("CREATE TABLE {} (id INT)"
1483+ .format (self ._table ))
1484+
1485+ try :
1486+ cur .execute ("CREATE USER {} IDENTIFIED BY '{}'" .format (self ._user , self ._password ), use_prepared_statements = False )
1487+ except errors .QueryError :
1488+ pass # User already exists
1489+ conn .commit ()
1490+
1491+ with self ._connect_user_pass (self ._user , self ._password ) as conn_2 :
1492+ cur_2 = conn_2 .cursor ()
1493+ for i in range (1 , 5 ):
1494+ with pytest .raises (errors .DatabaseError , match = 'Permission denied for relation {}' .format (self ._table )):
1495+ cur_2 .execute ("SELECT * FROM {} LIMIT 1" .format (self ._table ))
1496+ finally :
1497+ try :
1498+ cur .execute ("DROP USER {}" .format (self ._user ))
1499+ except errors .QueryError :
1500+ pass # User did not exist
0 commit comments