Hi,

I'm new to tg and sqlalchemy, I worte my simple sa model with some
integrity costraint such as unique=True

If i create a new database object for example

obj=DBObject(name='test',other='other')

and then save

DBSession.add(obj)

the first time all works fine, if I create the same object and try to
save the unique costraint is violated and my controller return a 500
error, obviously I try to use:

try:
   DBSession.add(obj)
except:
   pass

but nothing a TypeError: Already committed is raised,

I need to make a query before saving to check if the unique costraint
is violated? In my opinion a best solution is a way to trap the
dberror and show an error message to the users

another question:

if I use paster shell I have to issue transaction.commit() to make
database change, in tg2 controller seems that transaction.commit is
automatically called so is enough a DBSession.add(obj) is this
correct?

thanks
drakkan
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" 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/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to