Skip to content

Commit bc79953

Browse files
committed
Minor edits to the target_session_attrs patch.
1 parent 6043d91 commit bc79953

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

Diff for: asyncpg/connect_utils.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -611,21 +611,19 @@ def _parse_connect_dsn_and_args(*, dsn, host, port, user,
611611
'a Dict[str, str]')
612612

613613
if target_session_attrs is None:
614-
615614
target_session_attrs = os.getenv(
616615
"PGTARGETSESSIONATTRS", SessionAttribute.any
617616
)
618617
try:
619-
620618
target_session_attrs = SessionAttribute(target_session_attrs)
621-
except ValueError as exc:
619+
except ValueError:
622620
raise exceptions.InterfaceError(
623621
"target_session_attrs is expected to be one of "
624622
"{!r}"
625623
", got {!r}".format(
626624
SessionAttribute.__members__.values, target_session_attrs
627625
)
628-
) from exc
626+
) from None
629627

630628
params = _ConnectionParameters(
631629
user=user, password=password, database=database, ssl=ssl,

Diff for: asyncpg/connection.py

+15-12
Original file line numberDiff line numberDiff line change
@@ -2008,18 +2008,18 @@ async def connect(dsn=None, *,
20082008
If specified, check that the host has the correct attribute.
20092009
Can be one of:
20102010
2011-
"any": the first successfully connected host
2012-
"primary": the host must NOT be in hot standby mode
2013-
"standby": the host must be in hot standby mode
2014-
"read-write": the host must allow writes
2015-
"read-only": the host most NOT allow writes
2016-
"prefer-standby": first try to find a standby host, but if
2017-
none of the listed hosts is a standby server,
2018-
return any of them.
2019-
2020-
If not specified will try to use PGTARGETSESSIONATTRS
2021-
from the environment.
2022-
Defaults to "any" if no value is set.
2011+
- ``"any"`` - the first successfully connected host
2012+
- ``"primary"`` - the host must NOT be in hot standby mode
2013+
- ``"standby"`` - the host must be in hot standby mode
2014+
- ``"read-write"`` - the host must allow writes
2015+
- ``"read-only"`` - the host most NOT allow writes
2016+
- ``"prefer-standby"`` - first try to find a standby host, but if
2017+
none of the listed hosts is a standby server,
2018+
return any of them.
2019+
2020+
If not specified, the value parsed from the *dsn* argument is used,
2021+
or the value of the ``PGTARGETSESSIONATTRS`` environment variable,
2022+
or ``"any"`` if neither is specified.
20232023
20242024
:return: A :class:`~asyncpg.connection.Connection` instance.
20252025
@@ -2086,6 +2086,9 @@ async def connect(dsn=None, *,
20862086
.. versionchanged:: 0.26.0
20872087
Added the *direct_tls* parameter.
20882088
2089+
.. versionchanged:: 0.28.0
2090+
Added the *target_session_attrs* parameter.
2091+
20892092
.. _SSLContext: https://docs.python.org/3/library/ssl.html#ssl.SSLContext
20902093
.. _create_default_context:
20912094
https://docs.python.org/3/library/ssl.html#ssl.create_default_context

0 commit comments

Comments
 (0)