Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ pytest
pytest-timeout
python-dateutil
tox
parameterized
#kerberos
11 changes: 11 additions & 0 deletions vertica_python/tests/integration_tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ def _connect(cls):
"""
return connect(**cls._conn_info)

@classmethod
def _connect_user_pass(cls, user: str, password: str):
"""Connects to vertica with an overridden user/pass.

:return: a connection to vertica.
"""
conn_info = cls._conn_info.copy()
conn_info['user'] = user
conn_info['password'] = password
return connect(**conn_info)

@classmethod
def _get_node_num(cls):
"""Executes a query to get the number of nodes in the database
Expand Down
26 changes: 26 additions & 0 deletions vertica_python/tests/integration_tests/test_cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1193,6 +1193,8 @@ def setUpClass(cls):
def setUp(self):
super(PreparedStatementTestCase, self).setUp()
self._table = 'preparedstmt_test'
self._user = 'test_user'
self._password = 'TestPassword123'
with self._connect() as conn:
cur = conn.cursor()
cur.execute("DROP TABLE IF EXISTS {0}".format(self._table))
Expand Down Expand Up @@ -1472,3 +1474,27 @@ def test_bind_udtype(self):

self.assertEqual(cur.description[0].display_size, 10000)
self.assertEqual(cur.description[1].display_size, 1000)

def test_multiple_permission_error(self):
with self._connect() as conn:
try:
cur = conn.cursor()
cur.execute("CREATE TABLE {} (id INT)"
.format(self._table))

try:
cur.execute("CREATE USER {} IDENTIFIED BY '{}'".format(self._user, self._password), use_prepared_statements=False)
except errors.QueryError:
pass # User already exists
conn.commit()

with self._connect_user_pass(self._user, self._password) as conn_2:
cur_2 = conn_2.cursor()
for i in range(1, 5):
with pytest.raises(errors.DatabaseError, match='Permission denied for relation {}'.format(self._table)):
cur_2.execute("SELECT * FROM {} LIMIT 1".format(self._table))
finally:
try:
cur.execute("DROP USER {}".format(self._user))
except errors.QueryError:
pass # User did not exist
6 changes: 5 additions & 1 deletion vertica_python/vertica/cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,10 @@ def _error_handler(self, msg: BackendMessage) -> NoReturn:
self.connection.write(messages.Sync())
raise errors.QueryError.from_error_response(msg, self.operation)

def _prepared_statement_error_handler(self, msg: BackendMessage) -> NoReturn:
self._message = msg
raise errors.DatabaseError(msg.error_message())

def _prepare(self, query: str) -> None:
"""
Send the query to be prepared to the server. The server will parse the
Expand Down Expand Up @@ -1024,7 +1028,7 @@ def _execute_prepared_statement(self, list_of_parameter_values: Sequence[Any]) -
self.connection.write(messages.Flush())

# Read expected message: BindComplete
self.connection.read_expected_message(messages.BindComplete)
self.connection.read_expected_message(messages.BindComplete, self._prepared_statement_error_handler)

self._message = self.connection.read_message()
if isinstance(self._message, messages.ErrorResponse):
Expand Down