Skip to content

Canned queries with named parameters fail with error against SQLite 3.46.0 #2353

@simonw

Description

@simonw

Reported on Discord: https://discord.com/channels/823971286308356157/823971286941302908/1248924498128932914

I managed to replicate it locally using this trick https://til.simonwillison.net/sqlite/sqlite-version-macos-python

DYLD_LIBRARY_PATH=$PWD datasette fixtures.db -c datasette.yml --pdb

Where datasette.yml has this:

databases:
  fixtures:
    queries:
      demo: select * from sqlite_master where tbl_name = :table

Then navigate to http://127.0.0.1:8001/fixtures/demo

  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.10/site-packages/datasette/utils/__init__.py", line 1147, in derive_named_parameters
    return [row["p4"].lstrip(":") for row in results if row["opcode"] == "Variable"]
  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.10/site-packages/datasette/utils/__init__.py", line 1147, in <listcomp>
    return [row["p4"].lstrip(":") for row in results if row["opcode"] == "Variable"]
AttributeError: 'NoneType' object has no attribute 'lstrip'

Within the --pdb debugger I could see this:

(Pdb) pprint([dict(r) for r in results.rows])
[{'addr': 0,
  'comment': None,
  'opcode': 'Init',
  'p1': 0,
  'p2': 13,
  'p3': 0,
  'p4': None,
  'p5': 0},
 {'addr': 1,
  'comment': None,
  'opcode': 'OpenRead',
  'p1': 0,
  'p2': 1,
  'p3': 0,
  'p4': '5',
  'p5': 0},
 {'addr': 2,
  'comment': None,
  'opcode': 'Rewind',
  'p1': 0,
  'p2': 12,
  'p3': 0,
  'p4': None,
  'p5': 0},
 {'addr': 3,
  'comment': None,
  'opcode': 'Column',
  'p1': 0,
  'p2': 2,
  'p3': 1,
  'p4': None,
  'p5': 0},
 {'addr': 4,
  'comment': None,
  'opcode': 'Ne',
  'p1': 2,
  'p2': 11,
  'p3': 1,
  'p4': 'BINARY-8',
  'p5': 82},
 {'addr': 5,
  'comment': None,
  'opcode': 'Column',
  'p1': 0,
  'p2': 0,
  'p3': 3,
  'p4': None,
  'p5': 0},
 {'addr': 6,
  'comment': None,
  'opcode': 'Column',
  'p1': 0,
  'p2': 1,
  'p3': 4,
  'p4': None,
  'p5': 0},
 {'addr': 7,
  'comment': None,
  'opcode': 'Column',
  'p1': 0,
  'p2': 2,
  'p3': 5,
  'p4': None,
  'p5': 0},
 {'addr': 8,
  'comment': None,
  'opcode': 'Column',
  'p1': 0,
  'p2': 3,
  'p3': 6,
  'p4': None,
  'p5': 0},
 {'addr': 9,
  'comment': None,
  'opcode': 'Column',
  'p1': 0,
  'p2': 4,
  'p3': 7,
  'p4': None,
  'p5': 0},
 {'addr': 10,
  'comment': None,
  'opcode': 'ResultRow',
  'p1': 3,
  'p2': 5,
  'p3': 0,
  'p4': None,
  'p5': 0},
 {'addr': 11,
  'comment': None,
  'opcode': 'Next',
  'p1': 0,
  'p2': 3,
  'p3': 0,
  'p4': None,
  'p5': 1},
 {'addr': 12,
  'comment': None,
  'opcode': 'Halt',
  'p1': 0,
  'p2': 0,
  'p3': 0,
  'p4': None,
  'p5': 0},
 {'addr': 13,
  'comment': None,
  'opcode': 'Transaction',
  'p1': 0,
  'p2': 0,
  'p3': 35,
  'p4': '0',
  'p5': 1},
 {'addr': 14,
  'comment': None,
  'opcode': 'Variable',
  'p1': 1,
  'p2': 2,
  'p3': 0,
  'p4': None,
  'p5': 0},
 {'addr': 15,
  'comment': None,
  'opcode': 'Goto',
  'p1': 0,
  'p2': 1,
  'p3': 0,
  'p4': None,
  'p5': 0}]

Note that the Variable opcode now has p4 as None - and the name of the variable no longer appears in any of the opcodes!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions