Skip to content

Commit 8bc18cc

Browse files
author
Eugene Shershen
committed
handle server_settings and filter unsupported SQLAlchemy connection parameters
1 parent 8fdba32 commit 8bc18cc

1 file changed

Lines changed: 42 additions & 1 deletion

File tree

psqlpy_sqlalchemy/dbapi.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,49 @@ def __init__(self, psqlpy) -> None:
2929

3030
def connect(self, *arg, **kw):
3131
creator_fn = kw.pop("async_creator_fn", self.psqlpy.connect)
32+
33+
# Handle server_settings parameter that SQLAlchemy might pass
34+
server_settings = kw.pop("server_settings", None)
35+
if server_settings:
36+
# Map server_settings to individual psqlpy parameters
37+
if "application_name" in server_settings:
38+
kw["application_name"] = server_settings["application_name"]
39+
# Add other server_settings mappings as needed
40+
41+
# Filter out any other unsupported parameters that SQLAlchemy might pass
42+
supported_params = {
43+
"dsn",
44+
"username",
45+
"password",
46+
"host",
47+
"hosts",
48+
"port",
49+
"ports",
50+
"db_name",
51+
"target_session_attrs",
52+
"options",
53+
"application_name",
54+
"connect_timeout_sec",
55+
"connect_timeout_nanosec",
56+
"tcp_user_timeout_sec",
57+
"tcp_user_timeout_nanosec",
58+
"keepalives",
59+
"keepalives_idle_sec",
60+
"keepalives_idle_nanosec",
61+
"keepalives_interval_sec",
62+
"keepalives_interval_nanosec",
63+
"keepalives_retries",
64+
"load_balance_hosts",
65+
"max_db_pool_size",
66+
"conn_recycling_method",
67+
"ssl_mode",
68+
"ca_file",
69+
}
70+
71+
filtered_kw = {k: v for k, v in kw.items() if k in supported_params}
72+
3273
return AsyncAdapt_psqlpy_connection(
33-
self, await_only(creator_fn(*arg, **kw))
74+
self, await_only(creator_fn(*arg, **filtered_kw))
3475
)
3576

3677

0 commit comments

Comments
 (0)