Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
95fcd32
Added account_name to client and settings and connection, where clien…
ericf-firebolt Dec 15, 2021
1c2ae53
Merge branch 'main' into add-account_name-to-db-api
ericf-firebolt Dec 16, 2021
a0923fa
Added account_name where required in asynch connection.py.
ericf-firebolt Dec 16, 2021
2463801
Added account_name to unit/db/text_connection. Added clarifying notes…
ericf-firebolt Dec 19, 2021
f7d1547
Added account_name to Settings in unit/async_db/conftest.py.
ericf-firebolt Dec 19, 2021
50e6b41
Merged main with Mark Noack's edits.
ericf-firebolt Dec 19, 2021
97dc64b
Added account_name to readme_management.md. Added url and url_callbac…
ericf-firebolt Dec 19, 2021
1e8c25b
Edited tests/unit/async_db/test_connection.py to correct account_id u…
ericf-firebolt Dec 20, 2021
2798ed7
Added account_name to an object instantionation in async_db/connectio…
ericf-firebolt Dec 20, 2021
2ed47df
Added AccountNameError to deal with instances where an incorrect acco…
ericf-firebolt Dec 20, 2021
8048baa
Added invalid account name exception and error test.
ericf-firebolt Dec 20, 2021
c3ffb6b
Added test_invalid_account() to dbapi/sync/test_errors.py.
ericf-firebolt Dec 20, 2021
6668232
Added a bunch of periods to assertion error messages.
ericf-firebolt Dec 20, 2021
6402473
Changed account_name from Optional in FireboltClientMixin to satisfy …
ericf-firebolt Dec 21, 2021
9c3aea2
Try two to change account_name from Optional in FireboltClientMixin t…
ericf-firebolt Dec 21, 2021
65a10cd
Try three: changed account_name to Optional in async_connect_factory …
ericf-firebolt Dec 21, 2021
a21fcd4
Passed mypy by setting account_name to Optional[str] in _resolve_engi…
ericf-firebolt Dec 21, 2021
596d06a
Removed and replaced ENGINE_BY_NAME_URL with ACCOUNT_ENGINE_BY_NAME_U…
ericf-firebolt Dec 21, 2021
39174b9
Couldn't help myself: added a bunch of periods to test_queries_async.py.
ericf-firebolt Dec 22, 2021
7214c72
Removed unused _get_account_id() from service/manager.py.
ericf-firebolt Dec 22, 2021
15b80fe
Removed all edits to comments and documentation. Will be added in sep…
ericf-firebolt Dec 22, 2021
3bc8541
Fixed several typos in comments.
ericf-firebolt Dec 22, 2021
544d4bb
Fixed typos in some error messages.
ericf-firebolt Dec 22, 2021
f443766
Removed an extra call to retrieve account_id in connection.py.
ericf-firebolt Jan 5, 2022
d759756
Merged main. Hand merged failed auto-merge.
ericf-firebolt Jan 5, 2022
38de019
Changed AccountError to AccountNotFoundError and used httpx.codes for…
ericf-firebolt Jan 6, 2022
3508c74
Mistyped httpx in import in client.py.
ericf-firebolt Jan 6, 2022
0f2bfff
Removed accidental change from asyncio to trio in common/utils.py.
ericf-firebolt Jan 6, 2022
5f92642
Removed account_name completely from Connection class.
ericf-firebolt Jan 7, 2022
180bf05
Small cleanups to deal with a failed rebase.
ericf-firebolt Jan 10, 2022
0ee2d4e
Add @async_cached_property back to client.py.
ericf-firebolt Jan 10, 2022
c07aef7
Fixed await error caused by last commit.
ericf-firebolt Jan 10, 2022
4c96078
account_id_callback is unused in test_cursor_initialized in asynch_db…
ericf-firebolt Jan 10, 2022
ea61300
Fixed unit test errors caused by 0ee2d4ece9b08a63ac36e5562d3cd42e732a…
ericf-firebolt Jan 11, 2022
852ca2a
Updated logic on getting account_id from account_name in both unit/co…
ericf-firebolt Jan 11, 2022
730c111
Merge branch 'add-account_name-to-db-api' into fix-comments
ericf-firebolt Jan 11, 2022
3c1c6a8
More minor edits.
ericf-firebolt Jan 12, 2022
76d938b
Merge branch 'main' into fix-comments
ericf-firebolt Jan 12, 2022
2566760
Hand-merged failed auto-merge.
ericf-firebolt Jan 18, 2022
5a607ce
Merge branch 'main' into fix-comments
ericf-firebolt Jan 20, 2022
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
20 changes: 10 additions & 10 deletions src/firebolt/async_db/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ async def _resolve_engine_url(
response.raise_for_status()
return response.json()["engine"]["endpoint"]
except HTTPStatusError as e:
# Engine error would be 404
# Engine error would be 404.
if e.response.status_code != 404:
raise InterfaceError(f"unable to retrieve engine endpoint: {e}")
raise InterfaceError(f"Unable to retrieve engine endpoint: {e}.")
# Once this is point is reached we've already authenticated with
# the backend so it's safe to assume the cause of the error is
# missing engine
raise FireboltEngineError(f"Firebolt engine {engine_name} does not exist")
# missing engine.
raise FireboltEngineError(f"Firebolt engine {engine_name} does not exist.")
except (JSONDecodeError, RequestError, RuntimeError, HTTPStatusError) as e:
raise InterfaceError(f"unable to retrieve engine endpoint: {e}")
raise InterfaceError(f"Unable to retrieve engine endpoint: {e}.")


def async_connect_factory(connection_class: Type) -> Callable:
Expand All @@ -82,25 +82,25 @@ async def connect_inner(
api_endpoint(optional): Firebolt API endpoint. Used for authentication.

Note:
either `engine_name` or `engine_url` should be provided, but not both
Either `engine_name` or `engine_url` should be provided, but not both.

"""

if engine_name and engine_url:
raise InterfaceError(
"Both engine_name and engine_url are provided."
"Both engine_name and engine_url are provided. "
"Provide only one to connect."
)
if not engine_name and not engine_url:
raise InterfaceError(
"Neither engine_name nor engine_url are provided."
"Neither engine_name nor engine_url is provided. "
"Provide one to connect."
)

api_endpoint = fix_url_schema(api_endpoint)
# This parameters are optional in function signature,
# These parameters are optional in function signature
# but are required to connect.
# It's recommended to make them kwargs by PEP 249
# PEP 249 recommends making them kwargs.
for param, name in (
(database, "database"),
(username, "username"),
Expand Down
2 changes: 1 addition & 1 deletion src/firebolt/async_db/cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ async def _raise_if_error(self, resp: Response) -> None:
if not await is_engine_running(self.connection, self.connection.engine_url):
raise EngineNotRunningError(
f"Firebolt engine {self.connection.engine_url} "
"needs to be running to run queries against it"
"needs to be running to run queries against it."
)
resp.raise_for_status()

Expand Down
14 changes: 7 additions & 7 deletions src/firebolt/common/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ def __init__(self, method_name: str):

def __str__(self) -> str:
return (
f"unable to call {self.method_name}: "
f"engine must to be attached to a database first."
f"Unable to call {self.method_name}: "
f"Engine must to be attached to a database first."
)


Expand All @@ -43,8 +43,8 @@ def __init__(self, method_name: str):

def __str__(self) -> str:
return (
f"unable to call {self.method_name}: "
f"engine must not be in starting or stopping state."
f"Unable to call {self.method_name}: "
f"Engine must not be in starting or stopping state."
)


Expand All @@ -65,15 +65,15 @@ def __init__(self, method_name: str):
self.method_name = method_name

def __str__(self) -> str:
return f"unable to call {self.method_name}: cursor closed"
return f"Unable to call {self.method_name}: cursor closed."


class QueryNotRunError(CursorError):
def __init__(self, method_name: str):
self.method_name = method_name

def __str__(self) -> str:
return f"unable to call {self.method_name}: need to run a query first"
return f"Unable to call {self.method_name}: need to run a query first."


class QueryError(CursorError):
Expand All @@ -90,7 +90,7 @@ def __init__(self, cause: str, api_endpoint: str):
self.api_endpoint = api_endpoint

def __str__(self) -> str:
return f"Failed to authenticate at {self.api_endpoint}: {self.cause}"
return f"Failed to authenticate at {self.api_endpoint}: {self.cause}."


# PEP-249
Expand Down
2 changes: 1 addition & 1 deletion src/firebolt/db/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def close(self) -> None:
# Context manager support
def __enter__(self) -> Connection:
if self.closed:
raise ConnectionClosedError("Connection is already closed")
raise ConnectionClosedError("Connection is already closed.")
return self

def __exit__(
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/dbapi/async/test_auth_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ async def test_refresh_token(connection: Connection) -> None:
old = c._client.auth.token
c._client.auth._expires = int(time()) - 1

# Still works fine
# Still works fine.
await c.execute("show tables")

assert c._client.auth.token != old, "Auth didn't update token on expiration"
assert c._client.auth.token != old, "Auth didn't update token on expiration."


@mark.asyncio
Expand Down
16 changes: 8 additions & 8 deletions tests/integration/dbapi/async/test_errors_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
async def test_invalid_credentials(
engine_url: str, database_name: str, username: str, password: str, api_endpoint: str
) -> None:
"""Connection properly reacts to invalid credentials error"""
"""Connection properly reacts to invalid credentials error."""
async with await connect(
engine_url=engine_url,
database=database_name,
Expand Down Expand Up @@ -67,7 +67,7 @@ async def test_engine_url_not_exists(
account_name: str,
api_endpoint: str,
) -> None:
"""Connection properly reacts to invalid engine url error"""
"""Connection properly reacts to invalid engine url error."""
async with await connect(
engine_url=engine_url + "_",
database=database_name,
Expand All @@ -89,7 +89,7 @@ async def test_engine_name_not_exists(
account_name: str,
api_endpoint: str,
) -> None:
"""Connection properly reacts to invalid engine name error"""
"""Connection properly reacts to invalid engine name error."""
with raises(FireboltEngineError):
async with await connect(
engine_name=engine_name + "_________",
Expand All @@ -111,7 +111,7 @@ async def test_engine_stopped(
account_name: str,
api_endpoint: str,
) -> None:
"""Connection properly reacts to invalid engine name error"""
"""Connection properly reacts to invalid engine name error."""
with raises(EngineNotRunningError):
async with await connect(
engine_url=stopped_engine_url,
Expand All @@ -128,7 +128,7 @@ async def test_engine_stopped(
async def test_database_not_exists(
engine_url: str, database_name: str, username: str, password: str, api_endpoint: str
) -> None:
"""Connection properly reacts to invalid database error"""
"""Connection properly reacts to invalid database error."""
new_db_name = database_name + "_"
async with await connect(
engine_url=engine_url,
Expand All @@ -142,16 +142,16 @@ async def test_database_not_exists(

assert (
str(exc_info.value) == f"Database {new_db_name} does not exist"
), "Invalid database name error message"
), "Invalid database name error message."


@mark.asyncio
async def test_sql_error(connection: Connection) -> None:
"""Connection properly reacts to sql execution error"""
"""Connection properly reacts to SQL execution error."""
with connection.cursor() as c:
with raises(OperationalError) as exc_info:
await c.execute("select ]")

assert str(exc_info.value).startswith(
"Error executing query"
), "Invalid SQL error message"
), "Invalid SQL error message."
22 changes: 11 additions & 11 deletions tests/integration/dbapi/async/test_queries_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,17 @@ async def test_select(
async def test_drop_create(
connection: Connection, create_drop_description: List[Column]
) -> None:
"""Create and drop table/index queries are handled propperly"""
"""Create and drop table/index queries are handled properly."""

async def test_query(c: Cursor, query: str) -> None:
assert await c.execute(query) == 1, "Invalid row count returned"
assert c.rowcount == 1, "Invalid rowcount value"
assert await c.execute(query) == 1, "Invalid row count returned."
assert c.rowcount == 1, "Invalid rowcount value."
assert_deep_eq(
c.description,
create_drop_description,
"Invalid create table query description",
"Invalid create table query description.",
)
assert len(await c.fetchall()) == 1, "Invalid data returned"
assert len(await c.fetchall()) == 1, "Invalid data returned."

"""Create table query is handled properly"""
with connection.cursor() as c:
Expand Down Expand Up @@ -131,12 +131,12 @@ async def test_query(c: Cursor, query: str) -> None:

@mark.asyncio
async def test_insert(connection: Connection) -> None:
"""Insert and delete queries are handled propperly"""
"""Insert and delete queries are handled properly."""

async def test_empty_query(c: Cursor, query: str) -> None:
assert await c.execute(query) == -1, "Invalid row count returned"
assert c.rowcount == -1, "Invalid rowcount value"
assert c.description is None, "Invalid description"
assert await c.execute(query) == -1, "Invalid row count returned."
assert c.rowcount == -1, "Invalid rowcount value."
assert c.description is None, "Invalid description."
with raises(DataError):
await c.fetchone()

Expand All @@ -161,7 +161,7 @@ async def test_empty_query(c: Cursor, query: str) -> None:

assert (
await c.execute("SELECT * FROM test_tb ORDER BY test_tb.id") == 1
), "Invalid data length in table after insert"
), "Invalid data length in table after insert."

assert_deep_eq(
await c.fetchall(),
Expand All @@ -176,7 +176,7 @@ async def test_empty_query(c: Cursor, query: str) -> None:
[1, 2, 3],
],
],
"Invalid data in table after insert",
"Invalid data in table after insert.",
)


Expand Down
4 changes: 2 additions & 2 deletions tests/integration/dbapi/sync/test_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def test_engine_stopped(
def test_database_not_exists(
engine_url: str, database_name: str, username: str, password: str, api_endpoint: str
) -> None:
"""Connection properly reacts to invalid database error"""
"""Connection properly reacts to invalid database error."""
new_db_name = database_name + "_"
with connect(
engine_url=engine_url,
Expand All @@ -130,7 +130,7 @@ def test_database_not_exists(


def test_sql_error(connection: Connection) -> None:
"""Connection properly reacts to sql execution error"""
"""Connection properly reacts to sql execution error."""
with connection.cursor() as c:
with raises(OperationalError) as exc_info:
c.execute("select ]")
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/dbapi/sync/test_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_select(
def test_drop_create(
connection: Connection, create_drop_description: List[Column]
) -> None:
"""Create and drop table/index queries are handled propperly"""
"""Create and drop table/index queries are handled properly."""

def test_query(c: Cursor, query: str) -> None:
assert c.execute(query) == 1, "Invalid row count returned"
Expand Down Expand Up @@ -124,7 +124,7 @@ def test_query(c: Cursor, query: str) -> None:


def test_insert(connection: Connection) -> None:
"""Insert and delete queries are handled propperly"""
"""Insert and delete queries are handled properly."""

def test_empty_query(c: Cursor, query: str) -> None:
assert c.execute(query) == -1, "Invalid row count returned"
Expand Down
22 changes: 11 additions & 11 deletions tests/unit/async_db/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ async def test_closed_connection(connection: Connection) -> None:

@mark.asyncio
async def test_cursors_closed_on_close(connection: Connection) -> None:
"""Connection closes all it's cursors on close."""
"""Connection closes all its cursors on close."""
c1, c2 = connection.cursor(), connection.cursor()
assert (
len(connection._cursors) == 2
), "Invalid number of cursors stored in connection"
), "Invalid number of cursors stored in connection."

await connection.aclose()
assert connection.closed, "Connection was not closed on close"
assert c1.closed, "Cursor was not closed on connection close"
assert c2.closed, "Cursor was not closed on connection close"
assert len(connection._cursors) == 0, "Cursors left in connection after close"
assert connection.closed, "Connection was not closed on close."
assert c1.closed, "Cursor was not closed on connection close."
assert c2.closed, "Cursor was not closed on connection close."
assert len(connection._cursors) == 0, "Cursors left in connection after close."
await connection.aclose()


Expand All @@ -57,7 +57,7 @@ async def test_cursor_initialized(
query_url: str,
python_query_data: List[List[ColType]],
) -> None:
"""Connection initialised it's cursors propperly"""
"""Connection initialised its cursors properly."""
httpx_mock.add_callback(auth_callback, url=auth_url)
httpx_mock.add_callback(query_callback, url=query_url)

Expand All @@ -75,7 +75,7 @@ async def test_cursor_initialized(
cursor = connection.cursor()
assert (
cursor.connection == connection
), "Invalid cursor connection attribute"
), "Invalid cursor connection attribute."
assert (
cursor._client == connection._client
), "Invalid cursor _client attribute"
Expand All @@ -85,7 +85,7 @@ async def test_cursor_initialized(
cursor.close()
assert (
cursor not in connection._cursors
), "Cursor wasn't removed from connection after close"
), "Cursor wasn't removed from connection after close."


@mark.asyncio
Expand Down Expand Up @@ -136,7 +136,7 @@ async def test_connect_engine_name(
):
pass
assert str(exc_info.value).startswith(
"Both engine_name and engine_url are provided"
"Both engine_name and engine_url are provided."
)

with raises(InterfaceError) as exc_info:
Expand All @@ -148,7 +148,7 @@ async def test_connect_engine_name(
):
pass
assert str(exc_info.value).startswith(
"Neither engine_name nor engine_url are provided"
"Neither engine_name nor engine_url is provided."
)

httpx_mock.add_callback(auth_callback, url=auth_url)
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/client/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_auth_refresh_on_expiration(
execute_generator_requests(auth.auth_flow(Request("GET", "https://host")))
assert auth.token == test_token, "invalid access token"
execute_generator_requests(auth.auth_flow(Request("GET", "https://host")))
assert auth.token == test_token2, "expired access token was not updated"
assert auth.token == test_token2, "Expired access token was not updated."


def test_auth_uses_same_token_if_valid(
Expand Down Expand Up @@ -88,7 +88,7 @@ def test_auth_uses_same_token_if_valid(
execute_generator_requests(auth.auth_flow(Request("GET", "https://host")))
assert auth.token == test_token, "invalid access token"
execute_generator_requests(auth.auth_flow(Request("GET", "https://host")))
assert auth.token == test_token, "shoud not update token until it expires"
assert auth.token == test_token, "Should not update token until it expires."
httpx_mock.reset(False)


Expand Down Expand Up @@ -129,7 +129,7 @@ def http_error(**kwargs):
execute_generator_requests(auth.get_new_token_generator())

assert (
str(excinfo.value) == "Failed to authenticate at https://host: firebolt"
str(excinfo.value) == "Failed to authenticate at https://host: firebolt."
), "Invalid authentication error message"
httpx_mock.reset(True)

Expand Down
Loading