Using extension function in a VIEW causes exception to be printed

Open
#265 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
66/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
python, sqlite
Domain
cli, database

Research direction

Start by examining litecli/completion_refresher.py and litecli/sqlexecute.py, especially the background refresh and table_columns() query mentioned in the traceback. Reproduce with a SQLite view that uses an extension function unavailable to the connection, or open a database with such a view. Done means the CLI no longer prints an exception during completion refresh while the view remains usable.

Written by the indexing model from the issue text.

Description

With current git:

.load ./crypto -- included in popular sqlean extension for sqlite

CREATE TABLE products (
    product_id INTEGER PRIMARY KEY,
    product_name TEXT NOT NULL
);

INSERT INTO products (product_name) VALUES ('Wireless Mouse');

CREATE VIEW v_hashed_product_id AS
SELECT 
    hex(crypto_blake3(product_id))
FROM products;

Running this in the REPL prints out this exception:

  File "site-packages/litecli/completion_refresher.py", line 85, in _bg_refresh
    refresher(completer, executor)
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
  File "site-packages/litecli/completion_refresher.py", line 128, in refresh_tables
    table_cols = list(executor.table_columns())
  File "site-packages/litecli/sqlexecute.py", line 197, in table_columns
    cur.execute(self.table_columns_query)
    ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
sqlite3.OperationalError: no such function: crypto_blake3

but the view is created and works as expected.

Furthermore, existing and then opening the db in litecli also prints this exception:

$ litecli ./my.db
  File "site-packages/litecli/completion_refresher.py", line 85, in _bg_refresh
    refresher(completer, executor)
    ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
  File "site-packages/litecli/completion_refresher.py", line 128, in refresh_tables
    table_cols = list(executor.table_columns())
  File "site-packages/litecli/sqlexecute.py", line 197, in table_columns
    cur.execute(self.table_columns_query)
    ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
sqlite3.OperationalError: no such function: crypto_blake3
my.db>

Here's a link to sqlean binaries for testing.

Dominant language
Python
Stars
3.3k
Forks
95
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dbcli/litecli

All issues in dbcli/litecli

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.