Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l7x2Q-000317-5l for psycopg@arkaria.postgresql.org; Fri, 05 Feb 2021 09:04:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l7x2O-00074G-Uw for psycopg@arkaria.postgresql.org; Fri, 05 Feb 2021 09:04:24 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l7x2O-000749-K1 for psycopg@lists.postgresql.org; Fri, 05 Feb 2021 09:04:24 +0000 Received: from mail1.dalibo.net ([212.83.143.11] helo=mail.dalibo.com) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l7x2I-0007U7-9v for psycopg@postgresql.org; Fri, 05 Feb 2021 09:04:24 +0000 Received: from [192.168.0.29] (lan31-5-82-234-69-236.fbx.proxad.net [82.234.69.236]) by mail.dalibo.com (Postfix) with ESMTPSA id 36F4A206BC; Fri, 5 Feb 2021 10:04:16 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=dalibo.com; s=a; t=1612515856; bh=ElV9tbNl9dUhqri9AQx9adhipUw+FOkjHE9WqAWq5XQ=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=iHmANsoRWdBB0tpl/O0CV/nPCFyarOqYwIlT9zSnMK9xGI9lw6syjHTz/dt7Xu2KL IiTeTj8EpiPzd9smHs0Vw1eFtO6u/YTFVu4PXkkCuyFX8TUFE7ZzMk6txVelpOrsvI oa/cDr2Xsxmr3+HI+x0pybmqqJ3QtJKS6IsXT8jo= Subject: Re: about client-side cursors To: Christophe Pettus Cc: Daniele Varrazzo , psycopg@postgresql.org References: <20210203161548.vkhu3qkpvmgvyhik@dalibo.com> <20210204111647.4s3qie5cnassksa5@dalibo.com> <20210204172135.bl2boudpyw4vfahv@dalibo.com> From: Denis Laxalde Message-ID: Date: Fri, 5 Feb 2021 10:04:15 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Christophe Pettus a écrit : >> On Feb 4, 2021, at 09:21, Denis Laxalde 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. Well, that's just an exercise for me to understand where things happen. Of course, I'd expect an 'await' expression to possibly involve I/O in real life. > 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. That, and the fact that fetch*() methods do not fetch actually. (For the synchronous case, I'm quite convinced now this is too late to change.) >> 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. Worth retaining, maybe. Is it worth imposing the 'await cursor.fetch*()' pattern to everybody when it does not appear needed? I'm not so sure, as this would be at the cost of readability and clarity. (On the other hand, if I were to migrate some code to use server-side cursors, I would probably do it on a case-by-case basis; so if the cursor wasn't there in the first place, adding it would be little trouble in contrast to deciding where a server-side cursor is needed or not.)