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

get_table ignores ensure_schema flag #330

Closed astenuz closed 4 years ago

astenuz commented 4 years ago

Hi! As I understand, when connecting to a database we could set ensure_schema=False to avoid table and column creation. However, it seems this flag is ignored when accessing tables. For example, I believe it makes sense that when the flag is set to False, loading a non-existing table should raise an exception. However, it creates the table with a single id column:

import dataset

db = dataset.connect('<connection>', ensure_schema=False)

db['non_existing_table']  # creates the table, ignoring ensure_schema

This happens because get_table(...) (the method [] uses under the hood) directly calls create_table(...) without checking the flag

pudo commented 4 years ago

You're right, that behaviour is inconsistent. Fixing.