DataStax driver for Cassandra Version 3.25.0, Python version 3.9
Session.execute() fetches the first 100 records. As per the documentation, the driver is supposed to tranparently fetch next pages as we reach the end of first page. However, it fetches the same page again and again and hence the first 100 records is all that is ever accessible.
The for loop that prints records goes infinite.
ssl_context.verify_mode = CERT_NONE
cluster = Cluster(contact_points=[db_host], port=db_port,
auth_provider = PlainTextAuthProvider(db_user, db_pwd),
ssl_context=ssl_context
)
session = cluster.connect()
query = "SELECT * FROM content_usage"
statement = SimpleStatement(query, fetch_size=100)
results = session.execute(statement)
for row in results:
print(f"{row}")
I could see other similar threads, but they are not answered too. Has anyone encountered this issue before? Any help is appreciated.
The logic in your code is only calling
execute()
once so the contents ofresults
will only ever be the same list of 100 rows.You need to call
execute()
in your loop to get the next page of results like this:For more info, see Paging with the Python driver. Cheers!