Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data Type Mismatch Exceptions are raised as generic Exception and not TypeMismatchException #51

Closed
2 tasks done
d33bs opened this issue May 24, 2023 · 3 comments
Closed
2 tasks done

Comments

@d33bs
Copy link

d33bs commented May 24, 2023

What happens?

When querying data values which mismatch the column type in DuckDB using Python a generic duckdb.Exception is encountered instead of duckdb.TypeMismatchException. I'm opening this issue as it seemed there is an opportunity to better align existing exceptions so they may be handled appropriately within Python.

To Reproduce

import sqlite3

import duckdb

# create a temporary sqlite file location
filepath = ".example.sqlite"

# statements for creating database with simple structure
create_stmts = """
    DROP TABLE IF EXISTS tbl_a;
    CREATE TABLE tbl_a (
        col_integer INTEGER NOT NULL
        ,col_text TEXT
        ,col_blob BLOB
        ,col_real REAL
    );
    """

# some example values to insert into the database
insert_vals = ["nan", "sample", b"sample_blob", 0.5]

# create the database and insert some data into it
with sqlite3.connect(filepath) as connection:
    connection.executescript(create_stmts)

    connection.execute(
        (
            "INSERT INTO tbl_a (col_integer, col_text, col_blob, col_real)"
            "VALUES (?, ?, ?, ?);"
        ),
        insert_vals,
    )

try:
    duckdb.connect().execute(
        f"""
    /* install and load sqlite plugin for duckdb */
    INSTALL sqlite_scanner;
    LOAD sqlite_scanner;

    /* perform query on tbl_a table */
    SELECT * FROM sqlite_scan('{filepath}', 'tbl_a');
    """
    ).arrow()
    
except duckdb.TypeMismatchException as type_mismatch_e:
    print("Found a type mismatch exception: ", type_mismatch_e)
    
except Exception as e:
    print("Found a different error of type: ", type(e), e, sep="\n")

OS:

MacOS

SQLite Version:

3.37.0

DuckDB Version:

0.7.1, 0.8.0

DuckDB Client:

Python

Full Name:

Dave Bunten

Affiliation:

University of Colorado

Have you tried this on the latest master branch?

  • I agree

Have you tried the steps to reproduce? Do they include all relevant data and configuration? Does the issue you report still appear there?

  • I agree
@Mause
Copy link
Member

Mause commented Jun 6, 2023

This is probably caused by duckdb/duckdb#6521

@Mytherin
Copy link
Contributor

Mytherin commented Sep 4, 2024

This should be fixed now

@Mytherin Mytherin closed this as completed Sep 4, 2024
@d33bs
Copy link
Author

d33bs commented Sep 4, 2024

Cheers, thanks @Mause and @Mytherin for your help with this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants