From: Daniele Varrazzo Date: Wed, 24 Feb 2021 02:01:30 +0000 (+0100) Subject: Drop row_factory param from Connection.execute() X-Git-Tag: 3.0.dev0~106^2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a18c86dfd2a282a584246b0aadc0494739f8121b;p=thirdparty%2Fpsycopg.git Drop row_factory param from Connection.execute() The method is not present on cursor.execute: either it's on both or on none. Erring on the side of a less complex interface for the moment... --- diff --git a/docs/connection.rst b/docs/connection.rst index 698183106..e3e553f21 100644 --- a/docs/connection.rst +++ b/docs/connection.rst @@ -65,7 +65,7 @@ The `!Connection` class .. note:: You can use :ref:`with conn.cursor(): ...` to close the cursor automatically when the block is exited. - .. automethod:: execute(query, params=None, prepare=None, row_factory=None) -> Cursor + .. automethod:: execute(query, params=None, prepare=None) -> Cursor :param query: The query to execute. :type query: `!str`, `!bytes`, or `sql.Composable` @@ -74,9 +74,6 @@ The `!Connection` class :param prepare: Force (`!True`) or disallow (`!False`) preparation of the query. By default (`!None`) prepare automatically. See :ref:`prepared-statements`. - :param row_factory: Optional row factory to form result's row. See - :ref:`row-factories` for details. - :type row_factory: `Callable[[Cursor], Callable[[Sequence[Any]], Any]]` The cursor is what returned calling `cursor()` without parameters. The parameters are passed to its `~Cursor.execute()` and the cursor is @@ -211,7 +208,7 @@ The `!AsyncConnection` class .. note:: You can use ``async with conn.cursor() as cur: ...`` to close the cursor automatically when the block is exited. - .. automethod:: execute(query, params=None, prepare=None, row_factory=None) -> AsyncCursor + .. automethod:: execute(query, params=None, prepare=None) -> AsyncCursor .. automethod:: commit .. automethod:: rollback diff --git a/docs/row-factories.rst b/docs/row-factories.rst index 1c620e7c0..7b8919ac2 100644 --- a/docs/row-factories.rst +++ b/docs/row-factories.rst @@ -36,8 +36,8 @@ or as a plain function: return make_row These can then be used by specifying a `row_factory` argument in -`Connection.connect()`, `Connection.cursor()`, `Cursor.execute()` and -`Connection.execute()` or by writting to `Connection.row_factory` attribute. +`Connection.connect()`, `Connection.cursor()`, or by writing to +`Connection.row_factory` attribute. .. code:: python diff --git a/psycopg3/psycopg3/connection.py b/psycopg3/psycopg3/connection.py index d35eb68fd..3daa08b66 100644 --- a/psycopg3/psycopg3/connection.py +++ b/psycopg3/psycopg3/connection.py @@ -503,12 +503,9 @@ class Connection(BaseConnection): params: Optional[Params] = None, *, prepare: Optional[bool] = None, - row_factory: Optional[RowFactory] = _null_row_factory, ) -> Cursor: """Execute a query and return a cursor to read its results.""" - if row_factory is _null_row_factory: - row_factory = self.row_factory - cur = self.cursor(row_factory=row_factory) + cur = self.cursor() return cur.execute(query, params, prepare=prepare) def commit(self) -> None: @@ -675,11 +672,8 @@ class AsyncConnection(BaseConnection): params: Optional[Params] = None, *, prepare: Optional[bool] = None, - row_factory: Optional[RowFactory] = _null_row_factory, ) -> AsyncCursor: - if row_factory is _null_row_factory: - row_factory = self.row_factory - cur = self.cursor(row_factory=row_factory) + cur = self.cursor() return await cur.execute(query, params, prepare=prepare) async def commit(self) -> None: diff --git a/tests/test_connection.py b/tests/test_connection.py index c6b33b2fa..45b24dbb2 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -482,9 +482,6 @@ def test_execute(conn): cur = conn.execute("select 12, 22") assert cur.fetchone() == (12, 22) - cur = conn.execute("select 1, 2, 1, 2", row_factory=lambda cur: set) - assert cur.fetchone() == {1, 2} - def test_row_factory(dsn): conn = Connection.connect(dsn, row_factory=my_row_factory) @@ -493,9 +490,6 @@ def test_row_factory(dsn): cur = conn.execute("select 'a' as ve") assert cur.fetchone() == ["Ave"] - cur = conn.execute("select 'a' as ve", row_factory=None) - assert cur.fetchone() == ("a",) - with conn.cursor(row_factory=lambda c: set) as cur: cur.execute("select 1, 1, 2") assert cur.fetchall() == [{1, 2}] diff --git a/tests/test_connection_async.py b/tests/test_connection_async.py index 1e090cd51..4ba04e5ff 100644 --- a/tests/test_connection_async.py +++ b/tests/test_connection_async.py @@ -500,9 +500,6 @@ async def test_execute(aconn): cur = await aconn.execute("select 12, 22") assert await cur.fetchone() == (12, 22) - cur = await aconn.execute("select 1, 2, 1, 2", row_factory=lambda cur: set) - assert await cur.fetchone() == {1, 2} - async def test_row_factory(dsn): conn = await AsyncConnection.connect(dsn, row_factory=my_row_factory) @@ -511,9 +508,6 @@ async def test_row_factory(dsn): cur = await conn.execute("select 'a' as ve") assert await cur.fetchone() == ["Ave"] - cur = await conn.execute("select 'a' as ve", row_factory=None) - assert await cur.fetchone() == ("a",) - async with conn.cursor(row_factory=lambda c: set) as cur: await cur.execute("select 1, 1, 2") assert await cur.fetchall() == [{1, 2}]