Skip to content

Commit

Permalink
Minor edits to the target_session_attrs patch.
Browse files Browse the repository at this point in the history
  • Loading branch information
elprans committed Jul 6, 2023
1 parent 6043d91 commit bc79953
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
6 changes: 2 additions & 4 deletions asyncpg/connect_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,21 +611,19 @@ def _parse_connect_dsn_and_args(*, dsn, host, port, user,
'a Dict[str, str]')

if target_session_attrs is None:

target_session_attrs = os.getenv(
"PGTARGETSESSIONATTRS", SessionAttribute.any
)
try:

target_session_attrs = SessionAttribute(target_session_attrs)
except ValueError as exc:
except ValueError:
raise exceptions.InterfaceError(
"target_session_attrs is expected to be one of "
"{!r}"
", got {!r}".format(
SessionAttribute.__members__.values, target_session_attrs
)
) from exc
) from None

params = _ConnectionParameters(
user=user, password=password, database=database, ssl=ssl,
Expand Down
27 changes: 15 additions & 12 deletions asyncpg/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2008,18 +2008,18 @@ async def connect(dsn=None, *,
If specified, check that the host has the correct attribute.
Can be one of:
"any": the first successfully connected host
"primary": the host must NOT be in hot standby mode
"standby": the host must be in hot standby mode
"read-write": the host must allow writes
"read-only": the host most NOT allow writes
"prefer-standby": first try to find a standby host, but if
none of the listed hosts is a standby server,
return any of them.
If not specified will try to use PGTARGETSESSIONATTRS
from the environment.
Defaults to "any" if no value is set.
- ``"any"`` - the first successfully connected host
- ``"primary"`` - the host must NOT be in hot standby mode
- ``"standby"`` - the host must be in hot standby mode
- ``"read-write"`` - the host must allow writes
- ``"read-only"`` - the host most NOT allow writes
- ``"prefer-standby"`` - first try to find a standby host, but if
none of the listed hosts is a standby server,
return any of them.
If not specified, the value parsed from the *dsn* argument is used,
or the value of the ``PGTARGETSESSIONATTRS`` environment variable,
or ``"any"`` if neither is specified.
:return: A :class:`~asyncpg.connection.Connection` instance.
Expand Down Expand Up @@ -2086,6 +2086,9 @@ async def connect(dsn=None, *,
.. versionchanged:: 0.26.0
Added the *direct_tls* parameter.
.. versionchanged:: 0.28.0
Added the *target_session_attrs* parameter.
.. _SSLContext: https://docs.python.org/3/library/ssl.html#ssl.SSLContext
.. _create_default_context:
https://docs.python.org/3/library/ssl.html#ssl.create_default_context
Expand Down

0 comments on commit bc79953

Please sign in to comment.