Skip to content

Commit

Permalink
Fix memory leak with asyncpg, for SQLAlchemy generic functions (#273)
Browse files Browse the repository at this point in the history
Use SQLAlchemy caching logic for data type's result processors, instead
of handling it in this library.

Fixes #272
  • Loading branch information
adamantike authored Dec 10, 2020
1 parent 8cd5514 commit 05a52cd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ 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/).

## Unreleased

### Fixed

* Fix memory leak with asyncpg, for SQLAlchemy generic functions (#273)

## 0.4.1 (November 16th, 2020)

### Fixed
Expand Down
9 changes: 1 addition & 8 deletions databases/backends/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
logger = logging.getLogger("databases")


_result_processors = {} # type: dict


class PostgresBackend(DatabaseBackend):
def __init__(
self, database_url: typing.Union[DatabaseURL, str], **options: typing.Any
Expand Down Expand Up @@ -120,11 +117,7 @@ def __getitem__(self, key: typing.Any) -> typing.Any:
else:
idx, datatype = self._column_map[key]
raw = self._row[idx]
try:
processor = _result_processors[datatype]
except KeyError:
processor = datatype.result_processor(self._dialect, None)
_result_processors[datatype] = processor
processor = datatype._cached_result_processor(self._dialect, None)

if processor is not None:
return processor(raw)
Expand Down

0 comments on commit 05a52cd

Please sign in to comment.