why not query the database first to see whether the chosen name already exists? That's what i do in a validator function for a deform form. Other than the potentially superfluous database query I see no downside to this. regards robert
On Thu, Oct 27, 2011 at 2:51 PM, Mark Erbaugh <[email protected]> wrote: > I'm developing a Pyramid app with SQLAlchemy. > > I have a user registration page where user picks their user name and enter > other user-related information. The user name is the primary key in the > corresponding table. If the user picks a user name that is already in use by > another user, I need to inform the user of the fact and ask them to pick a > different user name. Pyramid apparently does an automatic commit of any > changes the the DBSession at the end of processing a page. When the record > with the duplicate primary key is inserted, SQLAlchemy raises an > IntegrityError exception as expected. > > My question is should I manually commit the DBsession inside a try ... except > block to catch and handle the exception in my page processing code, or should > I let the automatic commit fail and somehow trap the exception and process it > somewhere else, and if so, how and where do I trap the exception? > > Thanks, > Mark > > -- > 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.
