]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Drop row_factory param from Connection.execute()
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 24 Feb 2021 02:01:30 +0000 (03:01 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 24 Feb 2021 02:01:30 +0000 (03:01 +0100)
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...

docs/connection.rst
docs/row-factories.rst
psycopg3/psycopg3/connection.py
tests/test_connection.py
tests/test_connection_async.py

index 6981831067dae133bcbd40cba9f4c3a7926137d6..e3e553f212f639161b79f748fabccbf34eb28aeb 100644 (file)
@@ -65,7 +65,7 @@ The `!Connection` class
         .. note:: You can use :ref:`with conn.cursor(): ...<usage>`
             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
 
index 1c620e7c0900def9fb15b378d26c8cba0ea56c81..7b8919ac22ab07e12ad780684b647dfb1561f371 100644 (file)
@@ -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
 
index d35eb68fd29558ada60da65e24b0271dad7e259d..3daa08b66c2bf4fd9711540d2b49275b10d46e8d 100644 (file)
@@ -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:
index c6b33b2fa4145b04da53927730ef117356905ee7..45b24dbb2a6fd081c066adee521b7a8c839b9ddd 100644 (file)
@@ -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}]
index 1e090cd51b87d26563bc0ff01f27b67e0d1567a7..4ba04e5ff9db4ab350abfed6c86f48a458147233 100644 (file)
@@ -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}]