Skip to content

Commit

Permalink
Moved POSTGRES_URLS where it's used
Browse files Browse the repository at this point in the history
Pool creation uses explicit url with removed query params
  • Loading branch information
euri10 committed Jul 23, 2019
1 parent 17c7d9a commit 54d8d33
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
5 changes: 2 additions & 3 deletions databases/backends/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ def _get_connection_kwargs(self) -> dict:
async def connect(self) -> None:
assert self._pool is None, "DatabaseBackend is already running"
kwargs = self._get_connection_kwargs()
self._pool = await asyncpg.create_pool(
str(urlparse(self._database_url._url)._replace(query="").geturl()), **kwargs
)
url = str(self._database_url.replace(query=""))
self._pool = await asyncpg.create_pool(url, **kwargs)

async def disconnect(self) -> None:
assert self._pool is not None, "DatabaseBackend is not running"
Expand Down
5 changes: 4 additions & 1 deletion tests/test_connection_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
Unit tests for the backend connection arguments.
"""
from contextlib import suppress
from urllib.parse import urlparse

import pytest

from databases import Database
from databases.backends.mysql import MySQLBackend
from databases.backends.postgres import PostgresBackend
from tests.test_databases import POSTGRES_URLS, async_adapter
from tests.test_databases import async_adapter, DATABASE_URLS

POSTGRES_URLS = [url for url in DATABASE_URLS if urlparse(url).scheme == "postgresql"]


def test_postgres_pool_size():
Expand Down
2 changes: 0 additions & 2 deletions tests/test_databases.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import decimal
import functools
import os
from urllib.parse import urlparse

import pytest
import sqlalchemy
Expand All @@ -13,7 +12,6 @@
assert "TEST_DATABASE_URLS" in os.environ, "TEST_DATABASE_URLS is not set."

DATABASE_URLS = [url.strip() for url in os.environ["TEST_DATABASE_URLS"].split(",")]
POSTGRES_URLS = [url for url in DATABASE_URLS if urlparse(url).scheme == "postgresql"]


class MyEpochType(sqlalchemy.types.TypeDecorator):
Expand Down

0 comments on commit 54d8d33

Please sign in to comment.