Repository: pola-rs/polars
File: py-polars/polars/dataframe/frame.py (Python)

Code before:
                    catalog, db_schema = db_schema, None

                    # note: ADBC didnt't support 'replace' until adbc-driver-sqlite
                    # version 0.11 (it was released for other drivers in version 0.7)
                    if (
                        driver_manager_version >= (0, 7)
                        and adbc_driver_version < (0, 11)
                        and if_table_exists == "replace"
                    ):
                        cursor.execute(f"DROP TABLE IF EXISTS {table_name}")
                        mode = "create"

                # As of adbc_driver_manager 1.6.0, adbc_ingest can take a Polars
                # DataFrame via the PyCapsule interface
                data = self if driver_manager_version >= (1, 6) else self.to_arrow()

                # use of schema-qualified table names was released in
                # adbc-driver-manager 0.7.0 and is working without bugs from driver
                # version (e.g., adbc-driver-postgresql) version 0.8.0
                if driver_manager_version >= (0, 7) and adbc_driver_version >= (0, 8):
                    n_rows = cursor.adbc_ingest(
                        unpacked_table_name,
                        data=data,
                        mode=mode,
                        catalog_name=catalog,
                        db_schema_name=db_schema,
                        **(engine_options or {}),
                    )
                elif db_schema is not None:
                    adbc_driver_pypi_name = adbc_module_name.replace("_", "-")
                    msg = (
                        "use of schema-qualified table names requires "
                        "adbc-driver-manager version >= 0.7.0, found "
                        f"{driver_manager_str_version} and {adbc_driver_pypi_name} "
                        f"version >= 0.8.0, found {adbc_driver_str_version}"
                    )
                    raise ModuleUpgradeRequiredError(
                        # https://github.com/apache/arrow-adbc/issues/1000
                        # https://github.com/apache/arrow-adbc/issues/1109
                        msg
                    )
                else:
                    n_rows = cursor.adbc_ingest(
                        table_name=unpacked_table_name,
                        data=data,
                        mode=mode,
                        **(engine_options or {}),
                    )
                conn.commit()  # type: ignore[union-attr]
            return n_rows


Review comment (bug):
This check fixes https://github.com/pola-rs/polars/issues/24117.
Before the check was
`if adbc_version >= (0, 7)` 
(`adbc_version` is now renamed to `driver_manager_version`)
This incorrectly let through the buggy  `adbc-driver-postgresql==0.7.0`

Code after:
                    adbc_module_name, dbapi_submodule=False
                )
                adbc_driver_str_version = getattr(adbc_driver, "__version__", "0.0")
                adbc_driver_version = parse_version(adbc_driver_str_version)

                if adbc_module_name.split("_")[-1] == "sqlite":
                    catalog, db_schema = db_schema, None

                    # note: ADBC didnt't support 'replace' until adbc-driver-sqlite
                    # version 0.11 (it was released for other drivers in version 0.7)
                    if (
                        driver_manager_version >= (0, 7)
                        and adbc_driver_version < (0, 11)
                        and if_table_exists == "replace"
                    ):
                        cursor.execute(f"DROP TABLE IF EXISTS {table_name}")
                        mode = "create"

                # As of adbc_driver_manager 1.6.0, adbc_ingest can take a Polars
                # DataFrame via the PyCapsule interface
                data = self if driver_manager_version >= (1, 6) else self.to_arrow()

                # use of schema-qualified table names was released in
                # adbc-driver-manager 0.7.0 and is working without bugs from driver
                # version (e.g., adbc-driver-postgresql) version 0.8.0
                if driver_manager_version >= (0, 7) and adbc_driver_version >= (0, 8):
                    n_rows = cursor.adbc_ingest(
                        unpacked_table_name,
                        data=data,
                        mode=mode,
                        catalog_name=catalog,
                        db_schema_name=db_schema,
                        **(engine_options or {}),
                    )
                elif db_schema is not None:
                    adbc_driver_pypi_name = adbc_module_name.replace("_", "-")
                    msg = (
                        "use of schema-qualified table names requires "
                        "adbc-driver-manager version >= 0.7.0, found "
                        f"{driver_manager_str_version} and {adbc_driver_pypi_name} "
                        f"version >= 0.8.0, found {adbc_driver_str_version}"
                    )
                    raise ModuleUpgradeRequiredError(
                        # https://github.com/apache/arrow-adbc/issues/1000
                        # https://github.com/apache/arrow-adbc/issues/1109
                        msg
                    )
                else:
                    n_rows = cursor.adbc_ingest(
                        table_name=unpacked_table_name,
                        data=data,