-
Notifications
You must be signed in to change notification settings - Fork 419
Target session attr (2) #987
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 20 commits
bf6033c
bee17cb
1c67511
fae9d9c
7a847ce
a3d7342
7d9234f
a43b064
24ea4e5
3df816d
e24a091
38984a6
86423c3
277ed96
5737f76
c3133c0
ae325ba
980004c
3bc8322
4e97acc
d824333
08ad1f8
7cdd2ba
19b7a17
ea002ed
9f1d836
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
from . import serverversion | ||
from . import transaction | ||
from . import utils | ||
from .connect_utils import SessionAttribute | ||
|
||
|
||
class ConnectionMeta(type): | ||
|
@@ -1792,7 +1793,8 @@ async def connect(dsn=None, *, | |
direct_tls=False, | ||
connection_class=Connection, | ||
record_class=protocol.Record, | ||
server_settings=None): | ||
server_settings=None, | ||
target_session_attribute=SessionAttribute.any): | ||
r"""A coroutine to establish a connection to a PostgreSQL server. | ||
|
||
The connection parameters may be specified either as a connection | ||
|
@@ -2003,6 +2005,16 @@ async def connect(dsn=None, *, | |
this connection object. Must be a subclass of | ||
:class:`~asyncpg.Record`. | ||
|
||
:param SessionAttribute target_session_attribute: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. libpq uses |
||
If specified, check that the host has the correct attribute. | ||
Can be one of: | ||
"any": the first successfully connected host | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also |
||
"primary": the host must NOT be in hot standby mode | ||
"standby": the host must be in hot standby mode | ||
"prefer-standby": first try to find a standby host, but if | ||
none of the listed hosts is a standby server, | ||
return any of them. | ||
|
||
:return: A :class:`~asyncpg.connection.Connection` instance. | ||
|
||
Example: | ||
|
@@ -2087,6 +2099,15 @@ async def connect(dsn=None, *, | |
if record_class is not protocol.Record: | ||
_check_record_class(record_class) | ||
|
||
try: | ||
target_session_attribute = SessionAttribute(target_session_attribute) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please move this check to |
||
except ValueError as exc: | ||
raise exceptions.InterfaceError( | ||
"target_session_attribute is expected to be one of " | ||
"'any', 'primary', 'standby' or 'prefer-standby'" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest joining |
||
", got {!r}".format(target_session_attribute) | ||
) from exc | ||
|
||
if loop is None: | ||
loop = asyncio.get_event_loop() | ||
|
||
|
@@ -2109,6 +2130,7 @@ async def connect(dsn=None, *, | |
statement_cache_size=statement_cache_size, | ||
max_cached_statement_lifetime=max_cached_statement_lifetime, | ||
max_cacheable_statement_size=max_cacheable_statement_size, | ||
target_session_attribute=target_session_attribute | ||
) | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For improved libpq compatibility let's add support for the
PGTARGETSESSIONATTRS
environment variable also. Hence, the default here should beNone
(unspecified).