{"record":{"id":"711c8a519f44edf0","repo":"pola-rs/polars","slug":"cannot-set-iter-batches-for-self-driver-name-w","errorCode":null,"errorMessage":"Cannot set `iter_batches` for {self.driver_name} without also setting a non-zero `batch_size`","messagePattern":"Cannot set `iter_batches` for (.+?) without also setting a non-zero `batch_size`","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/io/database/_executor.py","lineNumber":246,"sourceCode":"                        \"adbc_driver_manager\" if driver == \"adbc\" else self.driver_name\n                    )\n                    # if the minimum version constraint is not met, try additional\n                    # driver properties with lower constraints\n                    try:\n                        self._check_module_version(driver_to_check, ver)\n                    except ModuleUpgradeRequiredError:\n                        if i < len(driver_properties_list):\n                            continue\n                        raise\n\n                if iter_batches and (\n                    driver_properties[\"exact_batch_size\"] and not batch_size\n                ):\n                    msg = (\n                        f\"Cannot set `iter_batches` for {self.driver_name} \"\n                        \"without also setting a non-zero `batch_size`\"\n                    )\n                    raise ValueError(msg)  # noqa: TRY301\n\n                frames = (\n                    self._apply_overrides(batch, (schema_overrides or {}))\n                    if isinstance(batch, DataFrame)\n                    else DataFrame(batch)\n                    for batch in self._fetch_arrow(\n                        driver_properties,\n                        iter_batches=iter_batches,\n                        batch_size=batch_size,\n                    )\n                )\n                return frames if iter_batches else next(frames)  # type: ignore[arg-type,return-value]\n        except Exception as err:\n            # eg: valid turbodbc/snowflake connection, but no arrow support\n            # compiled in to the underlying driver (or on this connection)\n            arrow_not_supported = (\n                \"does not support Apache Arrow\",\n                \"Apache Arrow format is not supported\",","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/pola-rs/polars/blob/df599052daf96e7a9cc30a3b0c6bd25d6947e3c0/py-polars/src/polars/io/database/_executor.py#L228-L264","documentation":"On the Arrow fetch path (_from_arrow), some drivers are registered with exact_batch_size=True, meaning their batched fetch method (e.g. fetch_arrow_batches / turbodbc's fetchallarrow with size) requires an explicit row count per batch. If you request iter_batches=True on such a driver without a non-zero batch_size, polars cannot construct the call and raises this ValueError naming the driver. This is raised inside the driver-properties loop after version checks, before any data is fetched.","triggerScenarios":"pl.read_database(q, connection=turbodbc_connection, iter_batches=True) with no batch_size; same for ADBC connections whose registry entry sets exact_batch_size and batch_size omitted or 0.","commonSituations":"Memory-conscious streaming reads where the author assumed polars would pick a default batch size; refactoring a working call by removing batch_size while keeping iter_batches.","solutions":["Pass a concrete batch size together with iter_batches: batch_size=50_000","Drop iter_batches to read the whole result as one Arrow table if memory allows","If you truly need unbounded streaming, switch to a driver/cursor whose fetch path does not require exact batch sizes"],"exampleFix":"# before\nfor df in pl.read_database(query, connection=conn, iter_batches=True):\n    ...\n\n# after\nfor df in pl.read_database(query, connection=conn, iter_batches=True,\n                           batch_size=50_000):\n    ...","handlingStrategy":"validation","validationCode":"if iter_batches and not batch_size:\n    batch_size = 50_000  # or raise, per your policy\nfor df in pl.read_database(query, connection=conn,\n                           iter_batches=iter_batches,\n                           batch_size=batch_size):\n    ...","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat iter_batches and batch_size as one coupled option - always set them together in helpers","Default batch_size explicitly at the API boundary of your data layer instead of relying on library defaults","Check the driver registry requirements for your driver before promising streaming reads"],"tags":["polars","database","arrow","iter-batches","batch-size","valueerror"],"backgroundTag":null,"analyzedSha":"df599052daf96e7a9cc30a3b0c6bd25d6947e3c0","analyzedAt":"2026-08-16T12:10:03.978Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}