Thread: plpython error since upgrading from 7.x to 8.x
I had a plpythonu function that worked in 7.x but since upgrading to 8.x it's giving this error: ERROR: plpython: function "notify" failed DETAIL: exceptions.TypeError: unsubscriptable object plpythonu IS installed in the database in which I'm trying to use the function. Any idea what the problem is? Thanks, CSN __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
On Wed, May 25, 2005 at 02:04:22AM -0700, CSN wrote: > > I had a plpythonu function that worked in 7.x but > since upgrading to 8.x it's giving this error: > > ERROR: plpython: function "notify" failed > DETAIL: exceptions.TypeError: unsubscriptable object Could you post a simple, self-contained example that exhibits this problem? Debugging would be easier if we could see what you're doing. -- Michael Fuhr http://www.fuhr.org/~mfuhr/
It happens when I try to insert rows: insert into table1 (col1, col2, col3) values (val1, val2, val3); I have an insert/update trigger on that table, and the plpythonu function just sends a notification email. Here's the function: if TD["new"]["active"] != TD["old"]["active"]: import smtplib import string fromaddr = "admin@mydomain.com" toaddr = "admin@yourdomain.com" if TD["new"]["active"] == 1: msg = "From: %s\r\nTo: %s\r\nSubject: Approved\r\n\r\n" % (fromaddr, toaddr) msg = msg + """Greetings, ... """ else: msg = "From: %s\r\nTo: %s\r\nSubject: New Record\r\n\r\n" % (fromaddr, toaddr) msg = msg + """Greetings, ... """ server = smtplib.SMTP("localhost") server.set_debuglevel(1) server.sendmail(fromaddr, toaddr, msg) server.quit() ##################### I also recently switched to Dbmail, so maybe that caused a problem (but mail works fine with everything else). CSN --- Michael Fuhr <mike@fuhr.org> wrote: > On Wed, May 25, 2005 at 02:04:22AM -0700, CSN wrote: > > > > I had a plpythonu function that worked in 7.x but > > since upgrading to 8.x it's giving this error: > > > > ERROR: plpython: function "notify" failed > > DETAIL: exceptions.TypeError: unsubscriptable > object > > Could you post a simple, self-contained example that > exhibits this > problem? Debugging would be easier if we could see > what you're doing. > > -- > Michael Fuhr > http://www.fuhr.org/~mfuhr/ > __________________________________ Yahoo! Mail Stay connected, organized, and protected. Take the tour: http://tour.mail.yahoo.com/mailtour.html
On Wed, May 25, 2005 at 12:02:22PM -0700, CSN wrote: > > It happens when I try to insert rows: > > insert into table1 (col1, col2, col3) values (val1, > val2, val3); > > I have an insert/update trigger on that table, and the > plpythonu function just sends a notification email. > Here's the function: > > > if TD["new"]["active"] != TD["old"]["active"]: Without a complete, self-contained example that succeeds in one version of PostgreSQL and fails in another, we still have to guess at what's going on. By "complete, self-contained example" I mean a sequence of SQL statements that anybody could load into an empty database and get the same results that you get. When putting together such an example, it's a good idea to reduce it as much as possible, i.e., keep removing things until you can't possibly make the example smaller and still get the behavior in question. Aside from making it easier for others to focus on the problem, sometimes the act of reducing the problem can help you find the problem on your own. My first guess would be that you're getting an error because when the event is INSERT, TD["old"] is None and thus unsubscriptable. But if that's the case then I'm not sure why the version of PostgreSQL would matter, and without seeing a complete example I'm not convinced that it does. Do you still get the error if you check if TD["event"] is "UPDATE" before trying to use TD["old"]? -- Michael Fuhr http://www.fuhr.org/~mfuhr/
Ah, you're right. The function appears to only cause an error on inserts and not updates. Thanks for pointing that out (I'm really green at Python). CSN --- Michael Fuhr <mike@fuhr.org> wrote: > On Wed, May 25, 2005 at 12:02:22PM -0700, CSN wrote: > > > > It happens when I try to insert rows: > > > > insert into table1 (col1, col2, col3) values > (val1, > > val2, val3); > > > > I have an insert/update trigger on that table, and > the > > plpythonu function just sends a notification > email. > > Here's the function: > > > > > > if TD["new"]["active"] != TD["old"]["active"]: > > Without a complete, self-contained example that > succeeds in one > version of PostgreSQL and fails in another, we still > have to guess > at what's going on. By "complete, self-contained > example" I mean > a sequence of SQL statements that anybody could load > into an empty > database and get the same results that you get. > When putting > together such an example, it's a good idea to reduce > it as much as > possible, i.e., keep removing things until you can't > possibly make > the example smaller and still get the behavior in > question. Aside > from making it easier for others to focus on the > problem, sometimes > the act of reducing the problem can help you find > the problem on > your own. > > My first guess would be that you're getting an error > because when > the event is INSERT, TD["old"] is None and thus > unsubscriptable. > But if that's the case then I'm not sure why the > version of PostgreSQL > would matter, and without seeing a complete example > I'm not convinced > that it does. Do you still get the error if you > check if TD["event"] > is "UPDATE" before trying to use TD["old"]? > > -- > Michael Fuhr > http://www.fuhr.org/~mfuhr/ > __________________________________ Do you Yahoo!? Yahoo! Small Business - Try our new Resources site http://smallbusiness.yahoo.com/resources/