simonw / db-to-sqlite

CLI tool for exporting tables or queries from any SQL database to a SQLite file
Apache License 2.0
368 stars 28 forks source link

StopIteration error thrown on empty tables #18

Closed simonw closed 3 years ago

simonw commented 5 years ago
(db-to-sqlite) bash-3.2$ python -i $(which db-to-sqlite) postgresql://localhost:5433/db --all db.db
Traceback (most recent call last):
  File "/Users/simonw/.local/share/virtualenvs/db-to-sqlite-CRf3fZQ-/bin/db-to-sqlite", line 11, in <module>
    load_entry_point('db-to-sqlite', 'console_scripts', 'db-to-sqlite')()
  File "/Users/simonw/.local/share/virtualenvs/db-to-sqlite-CRf3fZQ-/lib/python3.6/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/Users/simonw/.local/share/virtualenvs/db-to-sqlite-CRf3fZQ-/lib/python3.6/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/Users/simonw/.local/share/virtualenvs/db-to-sqlite-CRf3fZQ-/lib/python3.6/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/simonw/.local/share/virtualenvs/db-to-sqlite-CRf3fZQ-/lib/python3.6/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/Users/simonw/Desktop/Development/db-to-sqlite/db_to_sqlite/cli.py", line 103, in cli
    db[table].upsert_all(rows, pk=pk)
  File "/Users/simonw/.local/share/virtualenvs/db-to-sqlite-CRf3fZQ-/lib/python3.6/site-packages/sqlite_utils/db.py", line 1018, in upsert_all
    extracts=extracts,
  File "/Users/simonw/.local/share/virtualenvs/db-to-sqlite-CRf3fZQ-/lib/python3.6/site-packages/sqlite_utils/db.py", line 885, in insert_all
    first_record = next(records)
StopIteration

This is actually due to sqlite_utils being unable to handle empty lists passed to upsert_all.

simonw commented 5 years ago

Leaving this open to remind me to add a unit test.