simonw / datasette

An open source multi-tool for exploring and publishing data
https://datasette.io
Apache License 2.0
9.09k stars 649 forks source link

Datasette docker errors when db schema uses "strict" #2228

Open Darkle opened 6 months ago

Darkle commented 6 months ago

Hi, there seems to be an issue with the Datasette docker image when your db schema uses the STRICT feature.

Steps to reproduce:

  1. Create a db schema file schema.sql with the following:
    CREATE TABLE IF NOT EXISTS Foo (
    thing TEXT
    ) STRICT;
  2. Run sqlite3 ./db.db < ./schema.sql
  3. Run docker run -p 8001:8001 -v `pwd`:/mnt datasetteproject/datasette datasette -p 8001 -h 0.0.0.0 /mnt/db.db

The following error occurs:

Traceback (most recent call last):
  File "/usr/local/bin/datasette", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/datasette/cli.py", line 144, in wrapped
    return fn(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/datasette/cli.py", line 616, in serve
    asyncio.get_event_loop().run_until_complete(check_databases(ds))
  File "/usr/local/lib/python3.11/asyncio/base_events.py", line 650, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/datasette/cli.py", line 661, in check_databases
    await database.execute_fn(check_connection)
  File "/usr/local/lib/python3.11/site-packages/datasette/database.py", line 213, in execute_fn
    return await asyncio.get_event_loop().run_in_executor(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/datasette/database.py", line 211, in in_thread
    return fn(conn)
           ^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/datasette/utils/__init__.py", line 951, in check_connection
    for r in conn.execute(
             ^^^^^^^^^^^^^
sqlite3.DatabaseError: malformed database schema (Settings) - near "STRICT": syntax error

FWIW I tried an ubuntu docker image where I manually set up python and it seemed to work fine and didnt error:

FROM ubuntu:v23.10@sha256:8d093e0651575a6437cc4a3d561f892a345d263aeac6156ef378fe6a4ccabd4c AS build

RUN apt-get update
RUN DEBIAN_FRONTEND=noninteractive apt install python3 python3-pip -y
RUN pip install datasette --break-system-packages
RUN pip install datasette-query-history datasette-backup datasette-external-links-new-tabs datasette-pretty-json datasette-write-ui datasette-copyable --break-system-packages

EXPOSE 8001
CMD ["datasette"]
oryjkov commented 1 week ago

I've just ran into the same issue. Using a "strict" in table schema and can't open from docker. The same version of datasette (0.64.6) but installed on my host works fine.

Docker image has libsqlite3-0/now 3.34.1-3

While when running on host it gets: libsqlite3-0/jammy-security,jammy-updates,now 3.37.2-2ubuntu0.3