From e214b39b4434c10589b548c387ad9a0e9dd98d2c Mon Sep 17 00:00:00 2001 From: Alexis Metaireau Date: Sat, 30 Jul 2011 01:51:13 +0200 Subject: [PATCH] Fixes an unwanted error "user already exists". Doing a query with an AND SQL statement needs to be done with multiple "filter" callswith SQLAlchemy. Here, we want to be sure that the username is not used AND that the project is the same than the eventual users that would match. The previous version of the code returned an user with the same name, even if the user wasn't in the right group. --- budget/forms.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/budget/forms.py b/budget/forms.py index 1e265ee0..45da1f3c 100644 --- a/budget/forms.py +++ b/budget/forms.py @@ -44,6 +44,6 @@ class MemberForm(Form): submit = SubmitField("Add a member") def validate_name(form, field): - if Person.query.filter( - Person.name == field.data and Person.project == self.project).all(): + if Person.query.filter(Person.name == field.data)\ + .filter(Person.project == form.project).all(): raise ValidationError("This project already have this member")