Skip to content

Unable to catch error within stream for loop #382

@comodore31

Description

@comodore31

Python 3.9
Psycopg 3.0.8

Unable to catch psycopg.OperationalError

import asyncio
import psycopg

async def main():
    async with await psycopg.AsyncConnection.connect(conninfo='postgresql://xxxxxxxxxxxxxx') as con:
        async with con.cursor() as cur:
            try:
                async for r in cur.stream('select 1 a'):
                    raise NameError('Error here!')
            except:
                pass

if __name__ == '__main__':
    asyncio.run(main())

and we get the error

  File "psycopg_binary\\pq/pgconn.pyx", line 223, in psycopg_binary.pq.PGconn.send_query
psycopg.OperationalError: sending query failed: another command is already in progress

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions