apache / polaris

Apache Polaris, the interoperable, open source catalog for Apache Iceberg
https://polaris.apache.org/
Apache License 2.0
1.18k stars 133 forks source link

[BUG] Catalog endpoint for 'check if a table exists' returns <200> but should return <204> #471

Closed JasperHG90 closed 2 days ago

JasperHG90 commented 4 days ago

Is this a possible security vulnerability?

Describe the bug

The 'check if table exists' catalog endpoint returns status code <200>. The API docs indicate that it should return status code <204>. I initially posted this as a bug in the PyIceberg repository.

To Reproduce

Here's the script I posted in the PyIceberg issue

#%%

import httpx
import polars as pl
from pyiceberg.catalog import load_catalog

# Assumes this catalog exists and credentials stored in
#  .pyiceberg.yaml
# Possibly created using https://github.com/JasperHG90/dagster-pyiceberg-example-polaris/blob/main/scripts/set_up_catalog.py
catalog = load_catalog(
    name="dagster_example_catalog",
)

# %% Create a namespace

catalog.create_namespace("example")

# %% Create data and add to table

df = pl.from_dict({
    "a": [1, 2, 3],
    "b": [4, 5, 6]
}).to_arrow()

catalog.create_table(
    identifier="example.table",
    schema=df.schema
)

# %% This will return 'False'

catalog.table_exists("example.table")

# %% But querying the 'table exists' Polaris endpoint  returns 200

catalog_client = httpx.Client(
    base_url="http://polaris:8181/api/catalog/v1",
    headers={
        "Authorization": "Bearer principal:root;realm:default-realm",
        "Content-Type": "application/json",
    }
)

# See endpoint here: https://polaris.apache.org/in-dev/unreleased/rest-catalog-open-api/#tag/Catalog-API/operation/tableExists
resp = catalog_client.head(
    url="dagster_example_catalog/namespaces/example/tables/table"
)

resp.status_code # 200

This should work with any Polaris instance I suppose. The devcontainer that I use can be found here.

Actual Behavior

It returns a <200> status code.

Expected Behavior

It should return a <204> status code.

Additional context

N/A

System information

Ubuntu 22.04 LTS Polars SHA: 017ebbc

MonkeyCanCode commented 4 days ago

Checking

MonkeyCanCode commented 4 days ago

PR for fixing this issue: https://github.com/apache/polaris/pull/472/files