Exception handling with ZPsycopgDA
Howdy,
I'm using Zope 2.5.0 and ZPsycopgDA. I am having trouble handling execptions.
Zope hangs when I try. Here is the Python Script (not external) I use in
Zope:
# spend_time(proj_id, start_date, end_date, proj_plan)
#
# put time into database for weeks from start_date to end_date (inclusive)
#
# start_date and end_date are date strings that PostgreSQL understands
#
# proj_plan is a dictionary where the keys are category ids and the
# values are days spent over the time period.
#
import re
n_weeks = context.delta_weeks_from_dates(
start_date=start_date, end_date=end_date)[0].weeks
start_day = container.monday_from_date(date=start_date)[0].monday
end_day = container.monday_from_date(date=end_date)[0].monday
proj_name = context.projname_by_id(proj_id=proj_id)
bl_result = ""
bl_error = ""
for i in range(n_weeks):
# insert info for 'week'
for cat_id in proj_plan.keys():
try:
if float(proj_plan[cat_id]) >= 0.001:
q = """insert into spent_time (project,
category,
time,
username,
cal_week,
date_added)
values (%s,
%s,
'%s Days',
'%s',
'%s'::date + %d,
'now')""" % \
(proj_id, \
cat_id, \
float(proj_plan[cat_id]) / n_weeks, \
request.AUTHENTICATED_USER, \
start_day, i * 7)
# bl_result = bl_result + "%s<br>\n" % q
try:
context.genericQuery(query=q)
except StandardError, e:
bl_result = bl_result + "An error occured: " +str(e)
except:
pass
bl_result = bl_result + "%s: %s" % (proj_name, bl_error)
return bl_result
genericQuery is a ZSql method that takes on argument, a query string, and
executes it. It's contents are:
<dtml-var query>
When I call the python script and ZPsycopgDA raises an exception, Zope
hangs. Currently, the exception I am interested in handling is an
IntegrityError when a duplicate item is inserted.
Any help/guidance will be greatly appreciated.
Jeff.
--
--
Jeff Putsch Email: putsch@...
Maxim Integrated Products Office: (503)547-2037
High Frequency CAD Engineering