-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #258 from lsst-sqre/tickets/DM-44758
DM-44758: Drop safir.database.create_sync_session
- Loading branch information
Showing
4 changed files
with
30 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
### Backwards-incompatible changes | ||
|
||
- Drop `safir.database.create_sync_session`. This was only used by services that used Dramatiq for task management, since Dramatiq is sync-only. Services based on Safir should switch to arq and use only async database connections. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,6 @@ | |
_build_database_url, | ||
create_async_session, | ||
create_database_engine, | ||
create_sync_session, | ||
datetime_from_db, | ||
datetime_to_db, | ||
initialize_database, | ||
|
@@ -69,43 +68,28 @@ async def test_database_init(database_url: str) -> None: | |
|
||
|
||
def test_build_database_url(database_url: str) -> None: | ||
url = _build_database_url(database_url, None, is_async=False) | ||
assert url == database_url | ||
|
||
url = _build_database_url( | ||
"postgresql://[email protected]/foo", "password", is_async=False | ||
) | ||
assert url == "postgresql://foo:[email protected]/foo" | ||
|
||
url = _build_database_url( | ||
"postgresql://[email protected]/foo", None, is_async=True | ||
) | ||
url = _build_database_url("postgresql://[email protected]/foo", None) | ||
assert url == "postgresql+asyncpg://[email protected]/foo" | ||
|
||
url = _build_database_url( | ||
"postgresql://[email protected]:5432/foo", None, is_async=True | ||
) | ||
url = _build_database_url("postgresql://[email protected]:5432/foo", None) | ||
assert url == "postgresql+asyncpg://[email protected]:5432/foo" | ||
|
||
url = _build_database_url( | ||
"postgresql://[email protected]/foo", "otherpass", is_async=True | ||
) | ||
url = _build_database_url("postgresql://[email protected]/foo", "otherpass") | ||
assert url == "postgresql+asyncpg://foo:[email protected]/foo" | ||
|
||
url = _build_database_url( | ||
"postgresql://[email protected]:5433/foo", "otherpass", is_async=True | ||
"postgresql://[email protected]:5433/foo", "otherpass" | ||
) | ||
assert url == "postgresql+asyncpg://foo:[email protected]:5433/foo" | ||
|
||
# Test that the username and password are quoted properly. | ||
url = _build_database_url( | ||
"postgresql://foo%[email protected]:4444/foo", | ||
"pass@word/with stuff", | ||
is_async=False, | ||
) | ||
assert url == ( | ||
"postgresql://foo%40e.com:pass%40word%2Fwith%20stuff@127.0.0.1:4444" | ||
"/foo" | ||
"postgresql+asyncpg://foo%40e.com:pass%40word%2Fwith%20stuff" | ||
"@127.0.0.1:4444/foo" | ||
) | ||
parsed_url = urlparse(url) | ||
assert parsed_url.username | ||
|
@@ -142,36 +126,6 @@ async def test_create_async_session(database_url: str) -> None: | |
await engine.dispose() | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_create_sync_session(database_url: str) -> None: | ||
logger = structlog.get_logger(__name__) | ||
engine = create_database_engine(database_url, TEST_DATABASE_PASSWORD) | ||
await initialize_database(engine, logger, schema=Base.metadata, reset=True) | ||
await engine.dispose() | ||
|
||
session = create_sync_session( | ||
database_url, | ||
TEST_DATABASE_PASSWORD, | ||
logger, | ||
statement=select(User), | ||
) | ||
with session.begin(): | ||
session.add(User(username="foo")) | ||
session.remove() | ||
|
||
# Use a query against a non-existent table as the liveness check and | ||
# ensure that fails. | ||
metadata = MetaData() | ||
bad_table = Table("bad", metadata, Column("name", String(64))) | ||
with pytest.raises(ProgrammingError): | ||
session = create_sync_session( | ||
database_url, | ||
TEST_DATABASE_PASSWORD, | ||
logger, | ||
statement=select(bad_table), | ||
) | ||
|
||
|
||
def test_datetime() -> None: | ||
tz_aware = datetime.now(tz=UTC) | ||
tz_naive = tz_aware.replace(tzinfo=None) | ||
|