Re: about client-side cursors

From: Christophe Pettus <xof(at)thebuild(dot)com>
To: Denis Laxalde <denis(dot)laxalde(at)dalibo(dot)com>
Cc: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>, psycopg(at)postgresql(dot)org
Subject: Re: about client-side cursors
Date: 2021-02-04 17:31:22
Message-ID: D6A97A99-3F53-43CA-A01A-B72C39C0FA84@thebuild.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

> On Feb 4, 2021, at 09:21, Denis Laxalde <denis(dot)laxalde(at)dalibo(dot)com> wrote:
>
> Well, maybe I'm missing something... In the examples above, (written
> down explicitly to understand where IO happens), if I shut down postgres
> between 'await conn.execute()' and 'await cur.fetchall()', the first
> example breaks but the second doesn't. Perhaps the autocommit mention
> was misleading; it's enough to insert 'await conn.commit()' before
> 'await cur.fetchall()' to reproduce. So (and again, unless I'm missing
> something), if this is not "by design", maybe this is bug?

You're relying on private knowledge, not an API guarantee, as to "where I/O happens" here. Like any expectation based on private knowledge, you can get tripped up by that.

We shouldn't write into the API contract that either cursor.execute() or cursor.fetch*() are guaranteed not to fail with an I/O error. Any time you interact with the cursor object, that can be assumed to be an asynchronous operation that can fail due to the remote server not being available. Knowing that, you can reasonably code defensively no matter what.

Adding those explicit guarantees about I/O to the API hugely limits underlying implementation changes in the future, for as far as I can tell no real gain.

If it comes down to "cursor isn't a good name for this class," that's probably true, but we're a decade past making that decision.

> As far as the async interface is concerned, I think there is no adoption
> issue because there's no precedent use from psycopg2. So we could
> expose two API: cursorless querying ('await conn.execute()') and have a
> single server-side cursor class.

Right now, switching from using just a client-side cursor object to server-side cursor preserves largely preserves the API. I think that's a valuable feature that's worth retaining.

--
-- Christophe Pettus
xof(at)thebuild(dot)com

In response to

Responses

Browse psycopg by date

  From Date Subject
Next Message Denis Laxalde 2021-02-05 09:04:15 Re: about client-side cursors
Previous Message Denis Laxalde 2021-02-04 17:21:35 Re: about client-side cursors