Skip to content

Commit

Permalink
Merge branch 'master' into fix_postgres_keyerror
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb committed Jul 27, 2023
2 parents dfef796 + 25fa295 commit 158f967
Show file tree
Hide file tree
Showing 21 changed files with 712 additions and 158 deletions.
10 changes: 10 additions & 0 deletions .github/dependbot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "monthly"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: monthly
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ jobs:
runs-on: "ubuntu-latest"

steps:
- uses: "actions/checkout@v2"
- uses: "actions/setup-python@v1"
- uses: "actions/checkout@v3"
- uses: "actions/setup-python@v4"
with:
python-version: 3.7
- name: "Install dependencies"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ jobs:
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

steps:
- uses: "actions/checkout@v2"
- uses: "actions/setup-python@v1"
- uses: "actions/checkout@v3"
- uses: "actions/setup-python@v4"
with:
python-version: "${{ matrix.python-version }}"
- name: "Install dependencies"
Expand Down
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## 0.7.0 (Dec 18th, 2022)

### Fixed

* Fixed breaking changes in SQLAlchemy cursor; supports `>=1.4.42,<1.5` (#513).
* Wrapped types in `typing.Optional` where applicable (#510).

## 0.6.2 (Nov 7th, 2022)

### Changed

* Pinned SQLAlchemy `<=1.4.41` to avoid breaking changes (#520).

## 0.6.1 (Aug 9th, 2022)

### Fixed

* Improve typing for `Transaction` (#493)
* Allow string indexing into Record (#501)

## 0.6.0 (May 29th, 2022)

* Dropped Python 3.6 support (#458)
Expand Down
2 changes: 1 addition & 1 deletion databases/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from databases.core import Database, DatabaseURL

__version__ = "0.6.0"
__version__ = "0.7.0"
__all__ = ["Database", "DatabaseURL"]
5 changes: 3 additions & 2 deletions databases/backends/aiopg.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(
self._database_url = DatabaseURL(database_url)
self._options = options
self._dialect = self._get_dialect()
self._pool = None
self._pool: typing.Union[aiopg.Pool, None] = None

def _get_dialect(self) -> Dialect:
dialect = PGDialect_psycopg2(
Expand Down Expand Up @@ -104,7 +104,7 @@ class AiopgConnection(ConnectionBackend):
def __init__(self, database: AiopgBackend, dialect: Dialect):
self._database = database
self._dialect = dialect
self._connection = None # type: typing.Optional[aiopg.Connection]
self._connection: typing.Optional[aiopg.Connection] = None

async def acquire(self) -> None:
assert self._connection is None, "Connection is already acquired"
Expand Down Expand Up @@ -221,6 +221,7 @@ def _compile(
compiled._result_columns,
compiled._ordered_columns,
compiled._textual_ordered_columns,
compiled._ad_hoc_textual,
compiled._loose_column_name_matching,
)
else:
Expand Down
6 changes: 5 additions & 1 deletion databases/backends/asyncmy.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def _get_connection_kwargs(self) -> dict:
max_size = url_options.get("max_size")
pool_recycle = url_options.get("pool_recycle")
ssl = url_options.get("ssl")
unix_socket = url_options.get("unix_socket")

if min_size is not None:
kwargs["minsize"] = int(min_size)
Expand All @@ -49,6 +50,8 @@ def _get_connection_kwargs(self) -> dict:
kwargs["pool_recycle"] = int(pool_recycle)
if ssl is not None:
kwargs["ssl"] = {"true": True, "false": False}[ssl.lower()]
if unix_socket is not None:
kwargs["unix_socket"] = unix_socket

for key, value in self._options.items():
# Coerce 'min_size' and 'max_size' for consistency.
Expand Down Expand Up @@ -92,7 +95,7 @@ class AsyncMyConnection(ConnectionBackend):
def __init__(self, database: AsyncMyBackend, dialect: Dialect):
self._database = database
self._dialect = dialect
self._connection = None # type: typing.Optional[asyncmy.Connection]
self._connection: typing.Optional[asyncmy.Connection] = None

async def acquire(self) -> None:
assert self._connection is None, "Connection is already acquired"
Expand Down Expand Up @@ -211,6 +214,7 @@ def _compile(
compiled._result_columns,
compiled._ordered_columns,
compiled._textual_ordered_columns,
compiled._ad_hoc_textual,
compiled._loose_column_name_matching,
)
else:
Expand Down
6 changes: 5 additions & 1 deletion databases/backends/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def _get_connection_kwargs(self) -> dict:
max_size = url_options.get("max_size")
pool_recycle = url_options.get("pool_recycle")
ssl = url_options.get("ssl")
unix_socket = url_options.get("unix_socket")

if min_size is not None:
kwargs["minsize"] = int(min_size)
Expand All @@ -49,6 +50,8 @@ def _get_connection_kwargs(self) -> dict:
kwargs["pool_recycle"] = int(pool_recycle)
if ssl is not None:
kwargs["ssl"] = {"true": True, "false": False}[ssl.lower()]
if unix_socket is not None:
kwargs["unix_socket"] = unix_socket

for key, value in self._options.items():
# Coerce 'min_size' and 'max_size' for consistency.
Expand Down Expand Up @@ -92,7 +95,7 @@ class MySQLConnection(ConnectionBackend):
def __init__(self, database: MySQLBackend, dialect: Dialect):
self._database = database
self._dialect = dialect
self._connection = None # type: typing.Optional[aiomysql.Connection]
self._connection: typing.Optional[aiomysql.Connection] = None

async def acquire(self) -> None:
assert self._connection is None, "Connection is already acquired"
Expand Down Expand Up @@ -211,6 +214,7 @@ def _compile(
compiled._result_columns,
compiled._ordered_columns,
compiled._textual_ordered_columns,
compiled._ad_hoc_textual,
compiled._loose_column_name_matching,
)
else:
Expand Down
8 changes: 3 additions & 5 deletions databases/backends/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def _get_dialect(self) -> Dialect:
def _get_connection_kwargs(self) -> dict:
url_options = self._database_url.options

kwargs = {} # type: typing.Dict[str, typing.Any]
kwargs: typing.Dict[str, typing.Any] = {}
min_size = url_options.get("min_size")
max_size = url_options.get("max_size")
ssl = url_options.get("ssl")
Expand Down Expand Up @@ -165,7 +165,7 @@ class PostgresConnection(ConnectionBackend):
def __init__(self, database: PostgresBackend, dialect: Dialect):
self._database = database
self._dialect = dialect
self._connection = None # type: typing.Optional[asyncpg.connection.Connection]
self._connection: typing.Optional[asyncpg.connection.Connection] = None

async def acquire(self) -> None:
assert self._connection is None, "Connection is already acquired"
Expand Down Expand Up @@ -308,9 +308,7 @@ def raw_connection(self) -> asyncpg.connection.Connection:
class PostgresTransaction(TransactionBackend):
def __init__(self, connection: PostgresConnection):
self._connection = connection
self._transaction = (
None
) # type: typing.Optional[asyncpg.transaction.Transaction]
self._transaction: typing.Optional[asyncpg.transaction.Transaction] = None

async def start(
self, is_root: bool, extra_options: typing.Dict[typing.Any, typing.Any]
Expand Down
3 changes: 2 additions & 1 deletion databases/backends/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class SQLiteConnection(ConnectionBackend):
def __init__(self, pool: SQLitePool, dialect: Dialect):
self._pool = pool
self._dialect = dialect
self._connection = None # type: typing.Optional[aiosqlite.Connection]
self._connection: typing.Optional[aiosqlite.Connection] = None

async def acquire(self) -> None:
assert self._connection is None, "Connection is already acquired"
Expand Down Expand Up @@ -185,6 +185,7 @@ def _compile(
compiled._result_columns,
compiled._ordered_columns,
compiled._textual_ordered_columns,
compiled._ad_hoc_textual,
compiled._loose_column_name_matching,
)

Expand Down

0 comments on commit 158f967

Please sign in to comment.