duckdb / duckdb-rs

Ergonomic bindings to duckdb for Rust
MIT License
474 stars 100 forks source link

BUG: duckdb::data_t* duckdb::Allocator::AllocateData(duckdb::idx_t): Assertion `size > 0' failed #334

Open OliverKillane opened 3 months ago

OliverKillane commented 3 months ago

Issue

Failing on constraints referring to an enum's value.

Reproduce

Go to this repo, and cargo test

#[cfg(test)]
mod tests {
    use duckdb::{params, Connection};

    #[test]
    fn incorrect_behaviour() {
        let conn = Connection::open_in_memory().unwrap();
        conn.execute_batch(
            "
            CREATE TYPE MyEnum AS ENUM ('A');
            CREATE TABLE purchases (
                currency MyEnum NOT NULL,
                CHECK (
                    currency = 'A'
                )
            );
        ",
        )
        .unwrap();
        conn.execute(
            "
         INSERT INTO purchases (currency) VALUES ('A'::MyEnum)
        ",
            params![],
        )
        .unwrap();
    }

    #[test]
    fn correct_behaviour() {
        let conn = Connection::open_in_memory().unwrap();
        conn.execute_batch(
            "
            CREATE TYPE MyEnum AS ENUM ('A');
            CREATE TABLE purchases (
                currency MyEnum NOT NULL,
            );
        ",
        )
        .unwrap();
        conn.execute(
            "
         INSERT INTO purchases (currency) VALUES ('A'::MyEnum)
        ",
            params![],
        )
        .unwrap();
    }
}

Incorrect causes:

duckdb_allocator_size_0_assert-55c63b607dff2947: duckdb/src/common/allocator.cpp:122: duckdb::data_t* duckdb::Allocator::AllocateData(duckdb::idx_t): Assertion `size > 0' failed.
carlopi commented 3 months ago

Might be already fixed by https://github.com/duckdb/duckdb/pull/12370 ?