Close #259.
methods, but should be called using the `await` keyword.
.. automethod:: connect
+
+ .. versionchanged:: 3.1
+
+ Automatically resolve domain names asynchronously. In previous
+ versions, name resolution blocks, unless the ``hostaddr``
+ parameter is specified, or the `~psycopg._dns.resolve_hostaddr_async()`
+ function is used.
+
.. automethod:: close
.. note:: You can use ``async with`` to close the connection
.. _dnspython: https://dnspython.readthedocs.io/
-.. autofunction:: resolve_hostaddr_async
-
- .. note::
- One possible way to use this function automatically is to subclass
- `~psycopg.AsyncConnection`, extending the
- `~psycopg.AsyncConnection._get_connection_params()` method::
-
- import psycopg._dns # not imported automatically
-
- class AsyncDnsConnection(psycopg.AsyncConnection):
- @classmethod
- async def _get_connection_params(cls, conninfo, **kwargs):
- params = await super()._get_connection_params(conninfo, **kwargs)
- params = await psycopg._dns.resolve_hostaddr_async(params)
- return params
-
-
.. autofunction:: resolve_srv
.. warning::
.. warning::
This is an experimental method.
+
+
+.. autofunction:: resolve_hostaddr_async
+
+ .. note::
+ Starting from psycopg 3.1, a similar operation is performed
+ automatically by `!AsyncConnection._get_connection_params()`, so this
+ function is unneeded.
+
+ In psycopg 3.0, one possible way to use this function automatically is
+ to subclass `~psycopg.AsyncConnection`, extending the
+ `~psycopg.AsyncConnection._get_connection_params()` method::
+
+ import psycopg._dns # not imported automatically
+
+ class AsyncDnsConnection(psycopg.AsyncConnection):
+ @classmethod
+ async def _get_connection_params(cls, conninfo, **kwargs):
+ params = await super()._get_connection_params(conninfo, **kwargs)
+ params = await psycopg._dns.resolve_hostaddr_async(params)
+ return params
- `~Cursor.executemany()` performance improved by using batch mode internally
(:ticket:`#145`).
- Add parameters to `~Cursor.copy()`.
+- Resolve domain names asynchronously in `AsyncConnection.connect()`
+ (:ticket:`#259`).
- Add `pq.PGconn.trace()` and related trace functions (:ticket:`#167`).
- Add ``prepare_threshold`` parameter to `Connection` init (:ticket:`#200`).
- Add ``cursor_factory`` parameter to `Connection` init.
"""
Perform async DNS lookup of the hosts and return a new params dict.
+ .. deprecated:: 3.1
+ The use of this function is not necessary anymore, because
+ `psycopg.AsyncConnection.connect()` performs non-blocking name
+ resolution automatically.
+
:param params: The input parameters, for instance as returned by
`~psycopg.conninfo.conninfo_to_dict()`.
async def _get_connection_params(
cls, conninfo: str, **kwargs: Any
) -> Dict[str, Any]:
- """Manipulate connection parameters before connecting."""
+ """Manipulate connection parameters before connecting.
+
+ .. versionchanged:: 3.1
+ Unlike the sync counterpart, perform non-blocking address
+ resolution and populate the ``hostaddr`` connection parameter,
+ unless the user has provided one themselves. See
+ `~psycopg._dns.resolve_hostaddr_async()` for details.
+
+ """
params = conninfo_to_dict(conninfo, **kwargs)
# Make sure there is an usable connect_timeout