Validating SQLAlchemy enum before a save operaiton

时间:2015-06-30 13:32:25

标签: python python-2.7 sqlalchemy

Consider the following column definition:

group_name = db.Column(db.Enum('dogs', 'cats', name='device_group'))

Then in my API function I do:

lassie.group_name = userData.group
db.session.add(obj)
db.session.commit()

The problem that even if userData.group is treated as string in Python. Even if its value is "bird", until I actually do the commit operation, I will get no exception.

  • Why is SQLAlchemy is treating group_name as a string and not an enum?
  • How can I validate that the value I am putting on the object is an enum?
  • Should I perhaps use SQLAlchemy validator for that?

0 个答案:

没有答案