Comments (5)
It appears this issue is not just with polymorphic types, but with trying to save any ChoiceType column.
class User(Base):
__tablename__ = 'users'
TYPES = [
(u'customer', 'Customer'),
(u'admin', 'Admin'),
]
id = Column(Integer, primary_key=True)
type = Column(ChoiceType(TYPES), default='customer')
email = Column(String(180), unique=True)
is_active = Column(Boolean, default=True)
session.add(User(type=u'admin', email='test')
session.commit()
File "path/sqlalchemy-utils/sqlalchemy_utils/types/choice.py", line 107, in process_bind_param
return value.code
sqlalchemy.exc.StatementError: 'unicode' object has no attribute 'code' (original cause: AttributeError: 'unicode' object has no attribute 'code') u'INSERT INTO users (type, email, password,is_active) VALUES (?, ?, ?, ?, ?, ?, ?)' [{'type': u'admin', 'email': 'test'}]
So it appears the ChoiceType is completely broken, unless I'm missing something. The code should be something like:
def process_bind_param(self, value, dialect):
if isinstance(value, Choice):
return value.code
return value
from sqlalchemy-utils.
It seems you have not setup coercion_listener properly. See: http://sqlalchemy-utils.readthedocs.org/en/latest/coercion.html
from sqlalchemy-utils.
Tried with the coercion_listener, same error:
listen(mapper, 'mapper_configured', coercion_listener)
from sqlalchemy-utils.
DId you put the listener before the model definition? Clearly the problem is the unicode value does not get coerced to Choice object.
There is also a test case for this (which passes). So the problem must be with the data coercion. See: See: https://github.com/kvesteri/sqlalchemy-utils/blob/master/tests/types/test_choice.py#L39-L48
If you can reproduce the problem as a test case, that would be very helpful.
from sqlalchemy-utils.
Yes, tried placing the call before and after the model definition. It could however be an issue with the import of a base class in another module (i.e it's called after the base class is defined), so I'll investigate that possibility.
from sqlalchemy-utils.
Related Issues (20)
- create_view not accepting `replace` argument HOT 2
- Helper functions for explicit table locks ?
- custom aggregated column does not work with nullable=False
- Database_exist not working in python 3.11 HOT 1
- Even though binary was set false, impl remain binary(16)
- generic_relationship breaks with SqlAlchemy 2.0.22 HOT 3
- [Feature] Add MySQL collation support in `create_database`
- DeprecationWarning: 'crypt' is deprecated HOT 1
- Issue with change of implementation of EncryptedType from ‘LargeBinary’ to ‘String’ HOT 1
- [Feature] Enable Cascade Behavior for generic_relationship
- [Question] how to encrypt using aws kms in sqlalchemy
- Error on model with `server_default` for `DateTime` column and `UUIDType` primary key.
- [Feature] database helpers functions don't support custom create_engine()
- New release for SQLAlchemy >= 2.0.22 HOT 19
- Issue updating aggregate when setting foreign key to Null HOT 1
- Password checking error when using SQLAlchemy and Postgres
- [Feature] `auto_delete_orphans` not support `back_populates` HOT 2
- Does version 0.42.2 mix up with 0.41.2?
- With method ```create_view``` to construct a view ORM, then how to create corresponding database view? HOT 1
- Function `database_exists` stalls when inside a docker container
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sqlalchemy-utils.