Note also that TurboGears 0.9 makes the hub.begin(), commit() and end() automatic.
Kevin On 1/5/06, Olivier Favre-Simon <[EMAIL PROTECTED]> wrote: > Unless I miss something, this much more simple code should work: > > n = 'a subject' > hub.begin() > try: > rs = Subject.byName(n) > print "Found: %s" % rs > except SQLObjectNotFound: > print "%s Not Found! Creating..." % rs > rs = Subject(name=n) > hub.commit() > hub.end() > > of course you must have alternateID=True in your model, i.e. something like > > name = StringCol(alternateID=True, length=200) > > > Olivier. > > > Soni Bergraj wrote: > > Hello, > > I try to get a Subject from the database, if this fails i want to create > > a new one. But how ever i arrange hub.begin(), hub.end() and > > hub.commit() i always get an > > > > AssertionError: This transaction has already gone through ROLLBACK; > > begin another transaction > > > > For the except statement (object does not exist, create a new one) > > > > hub.begin() > > try: > > subject = Subject.byName(name) > > hub.commit > > hub.end() > > > > except SQLObjectNotFound: > > hub.end() > > hub.begin() > > subject = Subject(name = name) > > hub.commit() > > hub.end() > > > > The hub is of type PackageHub, I didn't found documentation for it > > (deprecated?). > > > > Thanks for help, > > > > > > > > -- Kevin Dangoor Author of the Zesty News RSS newsreader email: [EMAIL PROTECTED] company: http://www.BlazingThings.com blog: http://www.BlueSkyOnMars.com

