As the session is handled by TurboGears, I tried the following:

from turbogears.database import session
try:
    MyDBLog(
        myfield='A too long string xxxxxxxxxxxx'
    )
    session.commit()
    session.begin()
except Exception, e:
    log.error("Exception occurred with database logging: %s" % e)


It seems to work - however I'm not sure of the performance cost of
committing twice per web request.

Eoghan


On Sep 11, 6:53 pm, David Gardner <[EMAIL PROTECTED]> wrote:
> Depending on how your code is layed out you could wrap your
> session.flush() with a try:/catch I do something like this:
>
> session.begin()
> try:
>     ...
>     session.flush()
>     session.commit()
> except:
>     session.rollback()
>
>
>
> Eoghan Murray wrote:
> > Hi,
>
> > I've the following which generates an insert:
>
> > try:
> >     MyDBLog(
> >         myfield='A too long string xxxxxxxxxxxx'
> >     )
> > except Exception, e:
> >     log.error("Exception occurred with database logging: %s" % e)
>
> > Unfortunately, 'myfield' is (for example) a string of only length 10,
> > so the session fails with
> >     ProgrammingError: (ProgrammingError) value too long for type
> > character varying(10)
>
> > This error occurs at session commit time, so my 'except' clause above
> > is useless.
>
> > As 'MyDBLog' is not critical, I want to be able to ignore/log any kind
> > of Exception which the 'try' block above ultimately generates.  Is
> > there a way to do this?
>
> > Thanks!
>
> > Eoghan
>
> --
> David Gardner
> Pipeline Tools Programmer, "Sid the Science Kid"
> Jim Henson Creature Shop
> (323) 802-1717 [EMAIL PROTECTED]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to