Skip to content

IndexError when table view has binary column on right side of join #2601

@maxkapur

Description

@maxkapur

Consider a database with two tables, foo and bar, and a view foo_view that joins bar to foo based on the term column (sample_data.sqlite):

create table foo(term, value);
create table bar(term, definition, bytes);

insert into foo values ("text one", 1), ("text two", 2);
insert into bar values ("text one", "definition one", x'8af8ab88'), ("text two", "definition two", x'98246547');

create view foo_view as select foo.*, bar.* from foo join bar on foo.term = bar.term;

If I inspect this with datasette:

sqlite3 sample_data.db <sample_data.sqlite
datasette sample_data.db

and click on the foo_view table, the UI displays Error 500: No item with that key. The stacktrace in the terminal traces the IndexError to line 182 here:

def path_from_row_pks(row, pks, use_rowid, quote=True):
"""Generate an optionally tilde-encoded unique identifier
for a row from its primary keys."""
if use_rowid:
bits = [row["rowid"]]
else:
bits = [
row[pk]["value"] if isinstance(row[pk], dict) else row[pk] for pk in pks
]

This error occurs only when there is a blob column in foo.

The view loads just fine in the sqlite console:

sqlite> select * from foo_view;
text one|1|text one|definition one|����
text two|2|text two|definition two|�$eG

Environment info

$ datasette --version
datasette, version 1.0a22
$ python --version
Python 3.13.7
$ cat /etc/os-release 
PRETTY_NAME="Ubuntu 25.10"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions