[Sqlalchemy-tickets] Issue #3467: Array of enums does not allow assigning (zzzeek/sqlalchemy)
Brought to you by:
zzzeek
|
From: Wichert A. <iss...@bi...> - 2015-06-29 14:22:50
|
New issue 3467: Array of enums does not allow assigning https://bitbucket.org/zzzeek/sqlalchemy/issue/3467/array-of-enums-does-not-allow-assigning Wichert Akkerman: There is an overlap with #2940 here. I have an array of enums: ```python topping = sa.Enum('spinach', 'feta', 'pinenuts', name='topping') Base = declarative_base() class Pizza(Base): __tablename__ = 'pizza' id = sa.Column(sa.Integer(), primary_key=True) toppings = sa.Column(ARRAY(topping)) ``` With that minimal model I try to creating a new pizza instance with some toppings: ```python pizza = Pizza(toppings=['feta', 'spinach']) session.add(pizza) session.flush() ``` which results in this error: ``` Traceback (most recent call last): File "/Users/wichert/Jzoo/backend/lib/python3.4/site-packages/sqlalchemy/engine/base.py", line 1139, in _execute_context context) File "/Users/wichert/Jzoo/backend/lib/python3.4/site-packages/sqlalchemy/engine/default.py", line 442, in do_execute cursor.execute(statement, parameters) psycopg2.ProgrammingError: column "toppings" is of type topping[] but expression is of type text[] LINE 1: INSERT INTO pizza (toppings) VALUES (ARRAY['feta', 'spinach'... ^ HINT: You will need to rewrite or cast the expression. The above exception was the direct cause of the following exception: Traceback (most recent call last): File "x.py", line 25, in <module> session.flush() File "/Users/wichert/Jzoo/backend/lib/python3.4/site-packages/sqlalchemy/orm/session.py", line 2004, in flush self._flush(objects) File "/Users/wichert/Jzoo/backend/lib/python3.4/site-packages/sqlalchemy/orm/session.py", line 2122, in _flush transaction.rollback(_capture_exception=True) File "/Users/wichert/Jzoo/backend/lib/python3.4/site-packages/sqlalchemy/util/langhelpers.py", line 60, in __exit__ compat.reraise(exc_type, exc_value, exc_tb) File "/Users/wichert/Jzoo/backend/lib/python3.4/site-packages/sqlalchemy/util/compat.py", line 182, in reraise raise value File "/Users/wichert/Jzoo/backend/lib/python3.4/site-packages/sqlalchemy/orm/session.py", line 2086, in _flush flush_context.execute() File "/Users/wichert/Jzoo/backend/lib/python3.4/site-packages/sqlalchemy/orm/unitofwork.py", line 373, in execute rec.execute(self) File "/Users/wichert/Jzoo/backend/lib/python3.4/site-packages/sqlalchemy/orm/unitofwork.py", line 532, in execute uow File "/Users/wichert/Jzoo/backend/lib/python3.4/site-packages/sqlalchemy/orm/persistence.py", line 174, in save_obj mapper, table, insert) File "/Users/wichert/Jzoo/backend/lib/python3.4/site-packages/sqlalchemy/orm/persistence.py", line 761, in _emit_insert_statements execute(statement, params) File "/Users/wichert/Jzoo/backend/lib/python3.4/site-packages/sqlalchemy/engine/base.py", line 914, in execute return meth(self, multiparams, params) File "/Users/wichert/Jzoo/backend/lib/python3.4/site-packages/sqlalchemy/sql/elements.py", line 323, in _execute_on_connection return connection._execute_clauseelement(self, multiparams, params) File "/Users/wichert/Jzoo/backend/lib/python3.4/site-packages/sqlalchemy/engine/base.py", line 1010, in _execute_clauseelement compiled_sql, distilled_params File "/Users/wichert/Jzoo/backend/lib/python3.4/site-packages/sqlalchemy/engine/base.py", line 1146, in _execute_context context) File "/Users/wichert/Jzoo/backend/lib/python3.4/site-packages/sqlalchemy/engine/base.py", line 1339, in _handle_dbapi_exception exc_info File "/Users/wichert/Jzoo/backend/lib/python3.4/site-packages/sqlalchemy/util/compat.py", line 188, in raise_from_cause reraise(type(exception), exception, tb=exc_tb, cause=exc_value) File "/Users/wichert/Jzoo/backend/lib/python3.4/site-packages/sqlalchemy/util/compat.py", line 181, in reraise raise value.with_traceback(tb) File "/Users/wichert/Jzoo/backend/lib/python3.4/site-packages/sqlalchemy/engine/base.py", line 1139, in _execute_context context) File "/Users/wichert/Jzoo/backend/lib/python3.4/site-packages/sqlalchemy/engine/default.py", line 442, in do_execute cursor.execute(statement, parameters) sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) column "toppings" is of type topping[] but expression is of type text[] LINE 1: INSERT INTO pizza (toppings) VALUES (ARRAY['feta', 'spinach'... ^ HINT: You will need to rewrite or cast the expression. [SQL: 'INSERT INTO pizza (toppings) VALUES (%(toppings)s) RETURNING pizza.id'] [parameters: {'toppings': ['feta', 'spinach']}] ``` This is using SQLAlchemy 1.0.4 and psycopg2 2.5.4. |