Be careful about using an 'except' without specifying specific exception types -- that code will attempt an insert regardless of the reason for the failure in the 'try' clause. Anthony
On Saturday, July 2, 2011 6:05:46 PM UTC-4, Nick Arnett wrote: > Getting more comfortable with Web2Py and there sure is a lot to like about > it. > > I'm wondering what is considered best practice for inserting records that > might already exist, when I also want to get the id of the record if it does > exist. I haven't come across a shortcut for this. > > For now, I'm using a try statement, as below, for a table that stores web > page data: > > try: > urlID = db.web_page(url=url).id > except: > urlID = db.web_page.insert(url=url) > > I notice that early last year there was a discussion of how to create the > equivalent of Django's get_or_create(), which does this. I don't see that > that even made its way into Web2Py. > > NIck >