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

Commit 9e1aa48

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 9e1aa48

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

databases/backends/postgres.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ 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_lower = ssl.lower()
59+
if ssl_lower == "true":
60+
kwargs["ssl"] = True
61+
elif ssl_lower == "false":
62+
kwargs["ssl"] = False
5963

6064
kwargs.update(self._options)
6165

tests/test_connection_options.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ 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()

0 commit comments

Comments
 (0)