coleifer / sqlite-web

Web-based SQLite database browser written in Python
MIT License
3.35k stars 331 forks source link

Editing and deleting not working #121

Closed LunarTwilight closed 1 year ago

LunarTwilight commented 1 year ago

When I try to delete or edit a row I get this error

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/peewee.py", line 7024, in get
    return clone.execute(database)[0]
  File "/usr/local/lib/python3.10/dist-packages/peewee.py", line 4389, in __getitem__
    return self.row_cache[item]
IndexError: list index out of range

but there's also exceptions that happen when handling that exception apparently, and also the website shows a different error (along with exceptions that happened when handling that exception), so I'm not exactly sure what the issue is image

The errors only happen with some rows (seems like it might be due to it having a space or something?), trying to edit or delete other rows either shows the UI as expected, or returns a 404.

coleifer commented 1 year ago

Can you share the schema and an example row from the table that has the issue?

Looks like possibly peewee can't find the row you're trying to edit or delete, possibly because the serialization of the primary key has a problem somewhere.

coleifer commented 1 year ago

I've added a patch which fixes the TypeError -- this looks to be a situation where the serialization of your composite primary key has some kind of issue. Possibly the values that make up the key are very long?

If you can provide a minimal schema and an example failing row data so I can try to replicate, I'll be happy to reopen and provide a fix.

LunarTwilight commented 1 year ago

Updated to 0.5.2 and it's looking like it's due to the row containing NULL, as other rows that don't have a NULL value are fine.

The table's schema is

CREATE TABLE "filters"  (
  "regex"   TEXT,
  "action"  TEXT,
  "duration"    TEXT,
  "shouldDelete"    INTEGER
)

and for an example row, regex can be "example", action can be "alert", duration is NULL, and shouldDelete is 0.

coleifer commented 1 year ago

Does that table have a primary key? And if so are you using nullable values as part of the primary key? I think that might be the issue and I'd suggest that you probably ought to use an integer I'd or something along those lines...

LunarTwilight commented 1 year ago

Does that table have a primary key? And if so are you using nullable values as part of the primary key? I think that might be the issue and I'd suggest that you probably ought to use an integer I'd or something along those lines...

The table doesn't have a primary key

coleifer commented 1 year ago

Ok then that's your issue.

LunarTwilight commented 1 year ago

yep setting a primary key for the table fixed it, thanks

coleifer commented 1 year ago

If there is no primary key I was thinking that it wouldn't show any option to edit or delete, was that not the case? In other words I'm surprised you got an error, because I intended to check for the presence of a pk in order to allow those operations.

LunarTwilight commented 1 year ago

If there is no primary key I was thinking that it wouldn't show any option to edit or delete, was that not the case? In other words I'm surprised you got an error, because I intended to check for the presence of a pk in order to allow those operations.

There was an option to edit/delete for every row