simonw / db-to-sqlite

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

TypeError: 'NoneType' object is not iterable #24

Closed ojii closed 3 years ago

ojii commented 4 years ago

Trying to run db-to-sqlite --progress --all --skip alembic_version --redact users password_hash <redacted-postgres-url> dump.sqlite (using version 1.2.1) gives me this after/during foreign key handling.

The output (with tables aliased):

1/10: table_1
2/10: alembic_version
  ... skipping
3/10: table_2
4/10: table_3
5/10: table_4
6/10: table_5
7/10: table_6
8/10: table_7
9/10: table_8
10/10: table_8

Adding 9 foreign keys
  table_2.column_1 => table_1.id
  table_3.column_2 => table_2.id
  table_3.column_3 => table_4.id
  table_4.column_1 => table_1.id
  table_6.column_4 => table_4.id
  table_6.column_2 => table_2.id
  table_6.column_1 => table_1.id
  table_7.column_5 => table_6.id
  table_7.column_3 => table_4.id
Traceback (most recent call last):
  File "/virtualenv/bin/db-to-sqlite", line 8, in <module>
    sys.exit(cli())
  File "/virtualenv/lib64/python3.7/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/virtualenv/lib64/python3.7/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/virtualenv/lib64/python3.7/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/virtualenv/lib64/python3.7/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/virtualenv/lib64/python3.7/site-packages/db_to_sqlite/cli.py", line 150, in cli
    db.index_foreign_keys()
  File "/virtualenv/lib64/python3.7/site-packages/sqlite_utils/db.py", line 423, in index_foreign_keys
    i.columns[0] for i in table.indexes if len(i.columns) == 1
  File "/virtualenv/lib64/python3.7/site-packages/sqlite_utils/db.py", line 585, in indexes
    for row in self.db.execute_returning_dicts(sql):
  File "/virtualenv/lib64/python3.7/site-packages/sqlite_utils/db.py", line 172, in execute_returning_dicts
    keys = [d[0] for d in cursor.description]
TypeError: 'NoneType' object is not iterable
simonw commented 3 years ago

I think this has been fixed by the empty tables stuff in #28 - please re-open with steps to reproduce if the error continues.