Skip to content
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

enums and decimals are not supported #403

Open
matecsaj opened this issue Nov 17, 2022 · 0 comments
Open

enums and decimals are not supported #403

matecsaj opened this issue Nov 17, 2022 · 0 comments

Comments

@matecsaj
Copy link

Code:

import dataset
from decimal import Decimal
from enum import Enum, unique


@unique
class CurrencyEnum(Enum):
    CAD = 'CAD'
    USD = 'USD'


db = dataset.connect('sqlite:///my_database.db')
table = db['money_table']

dirty_money = {'dirty_amount': Decimal('1.23'),
               'dirty_currency': CurrencyEnum.USD}

clean_money = {'clean_amount': float(dirty_money['dirty_amount']),
               'clean_currency': dirty_money['dirty_currency'].value}

table.insert(clean_money)
table.insert(dirty_money)

Clean money can be inserted but not dirty.

/Users/matecsaj/Documents/Projects/nugget_spiders/venv/bin/python /Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py --multiprocess --qt-support=auto --client 127.0.0.1 --port 54496 --file /Users/matecsaj/Library/Application Support/JetBrains/PyCharm2022.2/scratches/scratch.py 
Traceback (most recent call last):
  File "/Users/matecsaj/Documents/Projects/nugget_spiders/venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1900, in _execute_context
    self.dialect.do_execute(
  File "/Users/matecsaj/Documents/Projects/nugget_spiders/venv/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 736, in do_execute
    cursor.execute(statement, parameters)
sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/matecsaj/Documents/Projects/nugget_spiders/venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1943, in _execute_context
    self._handle_dbapi_exception(
  File "/Users/matecsaj/Documents/Projects/nugget_spiders/venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 2124, in _handle_dbapi_exception
    util.raise_(
  File "/Users/matecsaj/Documents/Projects/nugget_spiders/venv/lib/python3.10/site-packages/sqlalchemy/util/compat.py", line 210, in raise_
    raise exception
  File "/Users/matecsaj/Documents/Projects/nugget_spiders/venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1900, in _execute_context
    self.dialect.do_execute(
  File "/Users/matecsaj/Documents/Projects/nugget_spiders/venv/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 736, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.InterfaceError: (sqlite3.InterfaceError) Error binding parameter 0 - probably unsupported type.
[SQL: INSERT INTO money_table (dirty_amount, dirty_currency) VALUES (?, ?)]
[parameters: (Decimal('1.23'), <CurrencyEnum.USD: 'USD'>)]
(Background on this error at: https://sqlalche.me/e/14/rvf5)
Exception during reset or similar
Traceback (most recent call last):
  File "/Users/matecsaj/Documents/Projects/nugget_spiders/venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 757, in _finalize_fairy
    fairy._reset(pool, transaction_was_reset)
  File "/Users/matecsaj/Documents/Projects/nugget_spiders/venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 1016, in _reset
    pool._dialect.do_rollback(self)
  File "/Users/matecsaj/Documents/Projects/nugget_spiders/venv/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 683, in do_rollback
    dbapi_connection.rollback()
sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 123145578684416 and this is thread id 4534160832.
Exception closing connection <sqlite3.Connection object at 0x1089e7640>
Traceback (most recent call last):
  File "/Users/matecsaj/Documents/Projects/nugget_spiders/venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 757, in _finalize_fairy
    fairy._reset(pool, transaction_was_reset)
  File "/Users/matecsaj/Documents/Projects/nugget_spiders/venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 1016, in _reset
    pool._dialect.do_rollback(self)
  File "/Users/matecsaj/Documents/Projects/nugget_spiders/venv/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 683, in do_rollback
    dbapi_connection.rollback()
sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 123145578684416 and this is thread id 4534160832.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/matecsaj/Documents/Projects/nugget_spiders/venv/lib/python3.10/site-packages/sqlalchemy/pool/base.py", line 260, in _close_connection
    self._dialect.do_terminate(connection)
  File "/Users/matecsaj/Documents/Projects/nugget_spiders/venv/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 689, in do_terminate
    self.do_close(dbapi_connection)
  File "/Users/matecsaj/Documents/Projects/nugget_spiders/venv/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 692, in do_close
    dbapi_connection.close()
sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 123145578684416 and this is thread id 4534160832.

Process finished with exit code 1

Please add support for enums and decimals; otherwise, do type conversions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant