Yeah, generally that's the basic idea of what was on my mind only I'm not interested in figuring out the integrity errors while the form is being filled out, but rather near when the user submits and .validate() is run on the form (pyramid_simpleform), which is when the colander validators are run. But yes, what I intended to do was avoid writing up extra validators that would do extra queries to check if a username is already in use (for example). I've no problem doing it, but it just seems like a bit of a hack. Although, to be honest, if I have to chose between the two I'd rather go with the extra validators than parsing an IntegrityError myself. In both cases, I'm having to repeat a lot of code if I have a good number of models each with their own unique fields. I guess to make it as nice as possible I could go ahead and write up a function that'll check a duplicate value against a particular model's field and use that with colander.Function.
Saludos, Carlos R. Gonzales On Fri, Apr 1, 2011 at 1:01 PM, Daniel Holth <[email protected]> wrote: > It sounds like you want to parse IntegrityError to provide nice error > messages and handle the race condition between the user pressing the 'is > this username still available?' button you should have on your form, and > submitting the form, and that you would rather have a rollback than an extra > query or two. > > I don't think you will have a very nice time parsing IntegrityError. IIRC > In SQLAlchemy you can just .add() and .flush() to get the potential > IntegrityError right away, and then re-validate all the unique fields on > your form (probably 1) for the user's edification. > > It's also quite possible, even likely, that a rollback may be more > expensive than the extra 'try not to screw it up' queries. > > Don't lose any sleep over the username-taken-while-form-being-filled-out > race condition. > > -- > You received this message because you are subscribed to the Google Groups > "pylons-discuss" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/pylons-discuss?hl=en. > -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
