Skip to content

Async select not returning all rows #331

@Subdued5455

Description

@Subdued5455
  1. What versions are you using?
    Oracle DB 19.22.0.0.0
    platform.platform: Linux-6.5.0-28-generic-x86_64-with-glibc2.35
    sys.maxsize > 2**32: True
    platform.python_version: 3.11.0rc1
    oracledb.version: 2.1.2
  1. Is it an error or a hang or a crash?
    An error.

  2. What error(s) or behavior you are seeing?
    When using async mode, fetches seem to end early. The issue seems to occur on every execution, though the exact number of rows returned is inconsistent. It works properly when using synchronous mode. I am relatively new to python, but believe the basic test code is correct - would be happy if this is just a problem of me doing something dumb. I am connecting to a database I have no control over.

Here is my script call and output:
python simple_test.py
Password:
async starting...
async connection acquired...
async cursor created...
async getting count(1)...
async getting rows...
async Elapsed Time: 35.00 seconds
async COUNT(1): 9375506
async total_fetched_rows: 32802
async cursor.rowcount: 32802

  1. Does your application call init_oracle_client()?
    No.
  1. Include a runnable Python script that shows the problem.
import asyncio
import oracledb
import getpass
import time


ORACLE_SOURCE_DSN=""
ORACLE_SOURCE_USER=""
ORACLE_SOURCE_PASS=""
    
async def async_test(table_name,pool):
    print(f"async starting...")
    start = time.time()
    total_fetched_rows = 0
    cursor_rowcount = 0
    async with oracledb.connect_async(user=ORACLE_SOURCE_USER,password=ORACLE_SOURCE_PASS,dsn=ORACLE_SOURCE_DSN) as connection:
        print(f"async connection acquired...")
        async with connection.cursor() as cursor:
            print(f"async cursor created...")
            print(f"async getting count(1)...")
            await cursor.execute(f"SELECT COUNT(1) FROM {table_name}")
            (row_count,) = await cursor.fetchone()
            print(f"async getting rows...")
            await cursor.execute(f'SELECT * FROM {table_name}')
            while True:
                rows = await cursor.fetchmany()
                if not rows:
                    break
                total_fetched_rows = total_fetched_rows + len(rows)
            cursor_rowcount = cursor.rowcount
    elapsed = time.time() - start
    print(f"async Elapsed Time: {elapsed:04.2f} seconds")
    print(f"async COUNT(1): {row_count}")
    print(f"async total_fetched_rows: {total_fetched_rows}")
    print(f"async cursor.rowcount: {cursor_rowcount}")

async def main():
    table_name = ""
    await async_test(table_name,pool=None)

ORACLE_SOURCE_PASS=getpass.getpass()
asyncio.run(main())

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions