Skip to content

Should detect collections.OrderedDict as a regular dictionary #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
simonw opened this issue Feb 16, 2020 · 2 comments
Closed

Should detect collections.OrderedDict as a regular dictionary #87

simonw opened this issue Feb 16, 2020 · 2 comments
Labels
bug Something isn't working

Comments

@simonw
Copy link
Owner

simonw commented Feb 16, 2020

  File "...python3.7/site-packages/sqlite_utils/db.py", line 292, in create_table
    column_type=COLUMN_TYPE_MAPPING[column_type],
KeyError: <class 'collections.OrderedDict'>
@simonw simonw added the bug Something isn't working label Feb 16, 2020
@simonw
Copy link
Owner Author

simonw commented Feb 16, 2020

Here's the code:

for key, types in all_column_types.items():
if len(types) == 1:
t = list(types)[0]
# But if it's list / tuple / dict, use str instead as we
# will be storing it as JSON in the table
if t in (list, tuple, dict):
t = str

@simonw
Copy link
Owner Author

simonw commented Feb 16, 2020

OrderedDict is actually a subclass of dict - so a smart fix would be for this logic to check and see if the type t is a subclass of one of list, tuple or dict.

@simonw simonw closed this as completed in 685e6a1 Feb 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant