pola-rs/polars · error · ValueError

cannot use credential_provider when passing a DeltaTable…

Error message

cannot use credential_provider when passing a DeltaTable object

What it means

When scan_delta receives a pre-constructed deltalake.DeltaTable object, a credential provider cannot be applied because credentials are resolved at catalog/storage time, not on an existing table handle. Passing credential_provider (other than 'auto') together with a DeltaTable raises ValueError.

Solutions

  1. Drop the credential_provider argument when passing a DeltaTable object
  2. Construct the DeltaTable with credentials/storage_options itself (deltalake handles providers at load time)
  3. Pass the table location string instead of the DeltaTable object if you need a custom credential provider

Example fix

// before
pl.scan_delta(delta_table, credential_provider=my_provider)
// after
pl.scan_delta(delta_table)
Defensive patterns

Strategy: type-guard

Validate before calling

if isinstance(table, DeltaTable) and credential_provider not in (None, 'auto'):
    credential_provider = None

Type guard

from deltalake import DeltaTable
def is_delta_table_handle(t):
    return isinstance(t, DeltaTable)

Try / catch

try:
    lf = pl.scan_delta(table, credential_provider=cp)
except ValueError as e:
    if 'credential_provider' in str(e):
        lf = pl.scan_delta(table)

Prevention

When it happens

Trigger: pl.scan_delta(delta_table_obj, credential_provider=my_provider) — i.e. table is a DeltaTable instance and credential_provider is not None/'auto'.

Common situations: Refactoring code from table-name/URI form to a DeltaTable object while leaving the credential_provider argument in place.

Related errors


AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18). Data as JSON: /api/errors/560ea031f923272d. Report an issue: GitHub.

Appendix: source

Thrown at py-polars/src/polars/io/delta/functions.py:318

    from polars.io.cloud.credential_provider._builder import (
        _init_credential_provider_builder,
    )

    table: DeltaTable | None = None

    if importlib.util.find_spec("deltalake") is not None:
        from deltalake import DeltaTable

        if isinstance(source, DeltaTable):
            table = source

    if table is None:
        credential_provider_builder = _init_credential_provider_builder(
            credential_provider, source, storage_options, "scan_delta"
        )
    elif credential_provider is not None and credential_provider != "auto":
        msg = "cannot use credential_provider when passing a DeltaTable object"
        raise ValueError(msg)
    else:
        credential_provider_builder = None

    del credential_provider

    if table is not None and (
        table._storage_options is not None or storage_options is not None
    ):
        storage_options = {
            **(table._storage_options or {}),
            **(storage_options or {}),
        }

    dataset = DeltaDataset(
        table_=NoPickleOption(table),
        table_uri_=str(source) if table is None else None,
        version=version,
        storage_options=storage_options,

View on GitHub (pinned to fe841f959e)