开发者

Sqlalchemy query not commiting

开发者 https://www.devze.com 2022-12-15 01:45 出处:网络
I\'m trying to create a simple unique username function for use in a Formencode schema. Here is the function:

I'm trying to create a simple unique username function for use in a Formencode schema. Here is the function:

class UniqueUsername(formencode.FancyValidator):   
    def _to_python(self, value, state):  
        user = DBSession.query(User.u开发者_如何学JAVAser_name).filter(User.username==value)  
        if user is not None:  
            raise formencode.Invalid(
            'That username already exists', value, state)  
        return value  

The problem is that the query gets generated but never actually hits the database. The user variable simply contains the generated query, not the query results. How do I go about fixing this? Thanks so much.


It should be:

user = DBSession.query(User.user_name).filter(User.username==value).first()

also: is it User.user_name or User.username ?

0

精彩评论

暂无评论...
验证码 换一张
取 消