AnswerDotAI / sqlite-minutils

A fork of sqlite-utils with CLI etc removed
https://AnswerDotAI.github.io/sqlite-minutils
Apache License 2.0
6 stars 6 forks source link

TypeError: unhashable type: 'list' when creating table with fks #2

Closed Chris2L closed 1 month ago

Chris2L commented 1 month ago

I'm using fasthtml with fastlite wrapper with this code:

from fasthtml.common import *

db = database('data/test.db')

authors = db.t.authors
if authors not in db.t:
    authors.create(id=int, name=str, pk='id')
    authors.create_index(columns=['name'], unique=True)
Author = authors.dataclass()

books = db.t.books
if books not in db.t:
    books.create(id=int, title=str, book_uid=str, author_fk=int, pk='id', foreign_keys=[('author_fk', 'authors', 'id')])
Book = books.dataclass()

When calling books.create, it ends up in sqlite_minutils/db.py in class Database's def create_table. After calling self.execute(sql) it tries to call self.table(....) to return the newly created table. It fails here with error TypeError: unhashable type: 'list'.

I can't seem to place the origin of the error. If it was type setting then it should have failed at sql = self.create_table_sql.

Any advice?

jph00 commented 1 month ago

I think this is fixed now - please reopen if I'm wrong.

Chris2L commented 1 month ago

Iv'e run

pip install -U sqlite-minutils

and it is now on version 3.37.0.post1 and I still get the error

jph00 commented 1 month ago

Actually sorry just realised there hadn't been a release since it was fixed. Just did one, so please re-check.

Chris2L commented 1 month ago

Resolved thank you