Skip to content
This repository was archived by the owner on Aug 19, 2025. It is now read-only.

Commit b7b0b91

Browse files
author
Elouan Martinet
committed
enabler(backends): allow ssl string parameters in PostgreSQL URL (#575)
The underlying library asyncpg accepts string values in the ssl parameter. The old code only accepted the values true and false, which are converted to boolean.
1 parent 2d05618 commit b7b0b91

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

databases/backends/postgres.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ def _get_connection_kwargs(self) -> dict:
5555
if max_size is not None:
5656
kwargs["max_size"] = int(max_size)
5757
if ssl is not None:
58-
kwargs["ssl"] = {"true": True, "false": False}[ssl.lower()]
58+
ssl = ssl.lower()
59+
kwargs["ssl"] = {"true": True, "false": False}.get(ssl, ssl)
5960

6061
kwargs.update(self._options)
6162

tests/test_connection_options.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,24 @@ def test_postgres_ssl():
4646
assert kwargs == {"ssl": True}
4747

4848

49+
def test_postgres_ssl_verify_full():
50+
backend = PostgresBackend("postgres://localhost/database?ssl=verify-full")
51+
kwargs = backend._get_connection_kwargs()
52+
assert kwargs == {"ssl": "verify-full"}
53+
54+
4955
def test_postgres_explicit_ssl():
5056
backend = PostgresBackend("postgres://localhost/database", ssl=True)
5157
kwargs = backend._get_connection_kwargs()
5258
assert kwargs == {"ssl": True}
5359

5460

61+
def test_postgres_explicit_ssl_verify_full():
62+
backend = PostgresBackend("postgres://localhost/database", ssl="verify-full")
63+
kwargs = backend._get_connection_kwargs()
64+
assert kwargs == {"ssl": "verify-full"}
65+
66+
5567
def test_postgres_no_extra_options():
5668
backend = PostgresBackend("postgres://localhost/database")
5769
kwargs = backend._get_connection_kwargs()

0 commit comments

Comments
 (0)