pudo / dataset

Easy-to-use data handling for SQL data stores with support for implicit table creation, bulk loading, and transactions.
https://dataset.readthedocs.org/
MIT License
4.78k stars 298 forks source link

Regression: `argument of type 'NoneType' is not iterable` when re-opening table #312

Closed Frankkkkk closed 4 years ago

Frankkkkk commented 4 years ago

Hi,

I've got an exception when I reopen a database and write inside it:

Traceback (most recent call last):
  File "app.py", line 11, in <module>
    t.insert({'xuid': uuid.uuid4().hex, 'name': ''})
  File "/usr/local/lib/python3.8/site-packages/dataset/table.py", line 103, in insert
    row = self._sync_columns(row, ensure, types=types)
  File "/usr/local/lib/python3.8/site-packages/dataset/table.py", line 376, in _sync_columns
    name = self._get_column_name(name)
  File "/usr/local/lib/python3.8/site-packages/dataset/table.py", line 83, in _get_column_name
    return self._column_keys.get(key, name)
  File "/usr/local/lib/python3.8/site-packages/dataset/table.py", line 64, in _column_keys
    if key in self._columns:
TypeError: argument of type 'NoneType' is not iterable

The example code is here: https://github.com/Frankkkkk/dataset-exception-example

And you can raise the exception like so:

$ docker build -t test .
Successfully tagged test:latest
$ sudo rm -rf db
$ docker run -v $(pwd)/db:/db -it test
$ docker run -v $(pwd)/db:/db -it test
Traceback (most recent call last):
  File "app.py", line 11, in <module>
    t.insert({'xuid': uuid.uuid4().hex, 'name': ''})
  File "/usr/local/lib/python3.8/site-packages/dataset/table.py", line 103, in insert
    row = self._sync_columns(row, ensure, types=types)
  File "/usr/local/lib/python3.8/site-packages/dataset/table.py", line 376, in _sync_columns
    name = self._get_column_name(name)
  File "/usr/local/lib/python3.8/site-packages/dataset/table.py", line 83, in _get_column_name
    return self._column_keys.get(key, name)
  File "/usr/local/lib/python3.8/site-packages/dataset/table.py", line 64, in _column_keys
    if key in self._columns:
TypeError: argument of type 'NoneType' is not iterable

This is a regression of version 1.2.1. It works with version 1.2.0

I'll try to make a patch if I've got time.

Cheers