On Mon, Jan 12, 2009 at 2:36 AM, drakkan <[email protected]> wrote:
>
> Thaks for your answers but maybe I haven't well explained the problem
>
> Please look at this examples:
>
> paster shell
>
> from sambadm.model.smbserver import *
> import transaction
>
> s=SambaShares(nome='testunique',path='/tmp/testunique')
> DBSession.add(s)
>
> try:
> transaction.commit()
> except:
> print 'error'
>
to start with you should never use except without the exception type,
your current code will catch even the interpreter running out of
memory (maybe not so far) but you should always catch the relevant
error not a generic one, that may be the source of your issue. I'm
almost certain that you "web request error" is that your eating up
TurboGears internal 404 handling which uses an exception.
as for the pattern you are using it makes little sense why will you
explicitly violate the constraint? I don't get it.
As for your last snip, the pattern to follow is, "ask for forgiveness
rather than permission". but your code is weird. the idiom I normally
use is:
instance = DBSession.query(...).one() or first()
if instance:
return dict(instance=instance)
else:
return dict(error='no records found')
you "add to the session" makes no sense there because you are saying
if the object you pulled from the db (and stored in existe) is not in
the db store it in the db.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---