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

Using IntEnum as an argument fails with TypeError #73

Open
oktavlachs opened this issue Jul 22, 2023 · 5 comments
Open

Using IntEnum as an argument fails with TypeError #73

oktavlachs opened this issue Jul 22, 2023 · 5 comments

Comments

@oktavlachs
Copy link

When using IntEnum values, the following Exception occurs.

  File "/code/.venv/lib/python3.11/site-packages/sqlalchemy/util/_compat_py3k.py", line 44, in __aexit__
    await self.gen.athrow(typ, value, traceback)
  File "/code/.venv/lib/python3.11/site-packages/sqlalchemy/dialects/mysql/asyncmy.py", line 188, in _mutex_and_adapt_errors
    yield
  File "/code/.venv/lib/python3.11/site-packages/sqlalchemy/dialects/mysql/asyncmy.py", line 104, in _execute_async
    result = await self._cursor.execute(operation, parameters)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "asyncmy/cursors.pyx", line 177, in execute
  File "asyncmy/cursors.pyx", line 155, in asyncmy.cursors.Cursor.mogrify
  File "asyncmy/cursors.pyx", line 128, in genexpr
  File "asyncmy/cursors.pyx", line 128, in genexpr
  File "asyncmy/connection.pyx", line 421, in asyncmy.connection.Connection.literal
  File "asyncmy/connection.pyx", line 414, in asyncmy.connection.Connection.escape
  File "asyncmy/converters.pyx", line 11, in asyncmy.converters.escape_item
  File "asyncmy/converters.pyx", line 26, in asyncmy.converters.escape_item
TypeError: Argument 'value' has incorrect type (expected str, got IdentityType)

I found you fixed this for string Enum already here.

Can you do the same for IntEnum? 🙏

Thanks for your work, I am looking forward to seeing this in production. 👍

@oktavlachs
Copy link
Author

I was using this in the context of FastAPI + SQLModel and solved it by using the SQLAlchemy Column class.

Column(Enum(IdentityType))

@oktavlachs
Copy link
Author

@long2ice Is there anything left for asnycmy from your perspective? Otherwise I would close this

@oktavlachs
Copy link
Author

@long2ice Actually, my workaround does not behave in the way I would like to. The SQLAlchemy Enum column type maps onto the enum column type of MySQL instead of integet. This column type is not supported by all DB technologies and actually I would prefer to map onto integer.

So I would say this issue is still valid.

@oktavlachs
Copy link
Author

For anyone else facing this and looking for a solution like I did, please find here a way to inject an IntEnum type in SQLAlchemy yourself:

https://stackoverflow.com/questions/33612625/how-to-model-enums-backed-by-integers-with-sqlachemy

@yuchi518
Copy link

I also look for a solution about this problem. Because my team's project used auto-map data model, it seems not be possible to use the solution which @oktavlachs provided?

Could be possible to fix this issue?

Very Thanks.

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

2 participants