Skip to content

things-cli fails with "sqlite3.OperationalError: unable to open database file" when listing a large number of todos (~2500)Β #125

@mbhutton

Description

@mbhutton

Note: solved, with an upcoming pull request, but filing here as a bug report for reference.

To Reproduce
Steps to reproduce the behavior:

  1. Create 2500 or so tasks (don't ask 😬)
  2. Run things-cli todos

Expected behavior
It runs successfully

Observed behaviour
It fails with the following:

Traceback (most recent call last):
  File "/Users/matt/.local/share/mh/uv-tool-bin/things-cli", line 8, in <module>
  File "/Users/matt/.local/share/uv/tools/things-cli/lib/python3.13/site-packages/things_cli/cli.py", line 487, in main
  File "/Users/matt/.local/share/uv/tools/things-cli/lib/python3.13/site-packages/things_cli/cli.py", line 406, in main
  File "/Users/matt/.local/share/uv/tools/things-cli/lib/python3.13/site-packages/things_cli/cli.py", line 422, in main
  File "/Users/matt/.local/share/uv/tools/things-cli/lib/python3.13/site-packages/things_cli/cli.py", line 479, in parse_command
  File "/Users/matt/.local/share/uv/tools/things-cli/lib/python3.13/site-packages/things/api.py", line 458, in todos
  File "/Users/matt/.local/share/uv/tools/things-cli/lib/python3.13/site-packages/things/api.py", line 206, in tasks
  File "/Users/matt/.local/share/uv/tools/things-cli/lib/python3.13/site-packages/things/database.py", line 395, in get_tags
  File "/Users/matt/.local/share/uv/tools/things-cli/lib/python3.13/site-packages/things/database.py", line 429, in get_tags_of_task
  File "/Users/matt/.local/share/uv/tools/things-cli/lib/python3.13/site-packages/things/database.py", line 500, in execute_query
sqlite3.OperationalError: unable to open database file
things-cli todos  0.09s user 0.02s system 61% cpu 0.178 total

Python: 3.13.0
things-cli: version 0.2.1

Root cause appears to be that each SQL query creates a new connection which is never closed, and so when querying tags for each task, the number of open connections is at least as high as the number of tasks.

Working fix is to close the connection each time after each query.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions