Validation when updating sqlalchemy order does not work

I have this class:

class User(base):
    __tablename__='User'
    name = Column(.......

    def __init__(self, name):
        self.name = name

    @validates('name')
    def validate_name(self, key, name):
        if blah blah blah:
            return name
        else:
            raise exception.....

create a new user and save it in the database ...

if __name__ == '__main__':
    user = User('foo')
    session.add(user)
    session.commit() #validation works here

when updating user:

if __name__ == '__main__':
    user = session.query(User).filter_by(name=='foo').first()
    user.name = 'bar'
    session.add(user)
    session.commit() #validation not working here

when saving a new user, a check is performed, but when updating an existing user, validation does not work.

Q: how to check a table column when updating its value with @validates?

Thank:)

+3
source share

All Articles