Skip to content

Transaction::commit succeeds on a read-only table #3462

Closed

Description

@mkroll-db

Apache Iceberg Rust version

v0.10.1

Describe the bug

Tables obtained via StaticTable::into_table can be written to, even though they should be read-only.
The internal code marks them as such but the write path has no check.

To Reproduce

The following example program succeeds, but should fail.

use std::collections::HashMap;

use iceberg::memory::{MEMORY_CATALOG_WAREHOUSE, MemoryCatalogBuilder};
use iceberg::spec::Schema;
use iceberg::table::StaticTable;
use iceberg::transaction::{ApplyTransactionAction, Transaction};
use iceberg::{Catalog, CatalogBuilder, NamespaceIdent, Result, TableCreation};

#[tokio::main]
async fn main() -> Result<()> {
    let catalog = MemoryCatalogBuilder::default()
        .load(
            "memory",
            HashMap::from([(
                MEMORY_CATALOG_WAREHOUSE.to_string(),
                "memory:///warehouse".to_string(),
            )]),
        )
        .await?;

    let ns = NamespaceIdent::new("ns".to_string());
    catalog.create_namespace(&ns, HashMap::new()).await?;
    let table = catalog
        .create_table(
            &ns,
            TableCreation::builder()
                .name("t".to_string())
                .schema(Schema::builder().build()?)
                .build(),
        )
        .await?;

    let readonly = StaticTable::from_metadata_file(
        table.metadata_location_result()?,
        table.identifier().clone(),
        table.file_io().clone(),
    )
    .await?
    .into_table();

    let tx = Transaction::new(&readonly);
    let tx = tx
        .update_table_properties()
        .set("written".to_string(), "yes".to_string())
        .apply(tx)?;

    tx.commit(&catalog).await?;
    println!("success writing to a read-only table");

    Ok(())
}

Expected behavior

Any commit to the table should be denied as it's clearly marked as read-only.

Willingness to contribute

I can contribute a fix for this bug independently

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions