plpython (triggers?) and dropped attributes

Поиск
Список
Период
Сортировка
Искать

plpython (triggers?) and dropped attributes

От:
"Arthur Ward" <award@dominionsciences.com>
Дата:
I have a table with a plpython trigger defined on it in 7.3.4. I've
dropped a column from that table, and now I cannot get a plpython trigger
to run at all on that table. I've dropped both the trigger and function
and recreated them from scratch (not using "create or replace"), and I
still get the following error when I set off the trigger:

ERROR:  plpython: Cache lookup for attribute
`........pg.dropped.5........' type `0' failed

The trigger procedure has a plpy.info call as the first statement, and I'm
not seeing that output, thus I believe it's a problem in plpython. I
suppose this is a bug in plpython's trigger handler building up the
TD['new'] and TD['old'] structures. I figured I'd toss this out and see if
somebody familiar with the plpython code can spot the problem faster than
if I start muddling through the code blindly.

Any thoughts?

Re: plpython (triggers?) and dropped attributes

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
"Arthur Ward"  writes:
> I have a table with a plpython trigger defined on it in 7.3.4. I've
> dropped a column from that table, and now I cannot get a plpython trigger
> to run at all on that table.

Would you try the attached patch?

			regards, tom lane

*** src/pl/plpython/plpython.c.orig	Wed Jun 11 14:33:46 2003
--- src/pl/plpython/plpython.c	Mon Sep 15 21:12:51 2003
***************
*** 586,594 ****
  	plkeys = PyDict_Keys(plntup);
  	natts = PyList_Size(plkeys);
  
- 	if (natts != proc->result.out.r.natts)
- 		elog(ERROR, "plpython: TD[\"new\"] has an incorrect number of keys.");
- 
  	modattrs = palloc(natts * sizeof(int));
  	modvalues = palloc(natts * sizeof(Datum));
  	for (i = 0; i < natts; i++)
--- 586,591 ----
***************
*** 622,628 ****
  
  		Py_INCREF(plval);
  
! 		if (plval != Py_None)
  		{
  			plstr = PyObject_Str(plval);
  			src = PyString_AsString(plstr);
--- 619,625 ----
  
  		Py_INCREF(plval);
  
! 		if (plval != Py_None && !tupdesc->attrs[atti]->attisdropped)
  		{
  			plstr = PyObject_Str(plval);
  			src = PyString_AsString(plstr);
***************
*** 1363,1368 ****
--- 1360,1368 ----
  		HeapTuple	typeTup;
  		Form_pg_type typeStruct;
  
+ 		if (desc->attrs[i]->attisdropped)
+ 			continue;
+ 
  		datum = ObjectIdGetDatum(desc->attrs[i]->atttypid);
  		typeTup = SearchSysCache(TYPEOID, datum, 0, 0, 0);
  		if (!HeapTupleIsValid(typeTup))
***************
*** 1403,1408 ****
--- 1403,1411 ----
  		HeapTuple	typeTup;
  		Form_pg_type typeStruct;
  
+ 		if (desc->attrs[i]->attisdropped)
+ 			continue;
+ 
  		datum = ObjectIdGetDatum(desc->attrs[i]->atttypid);
  		typeTup = SearchSysCache(TYPEOID, datum, 0, 0, 0);
  		if (!HeapTupleIsValid(typeTup))
***************
*** 1593,1598 ****
--- 1596,1604 ----
  					vdat;
  		bool		is_null;
  		PyObject   *value;
+ 
+ 		if (desc->attrs[i]->attisdropped)
+ 			continue;
  
  		key = NameStr(desc->attrs[i]->attname);
  		vattr = heap_getattr(tuple, (i + 1), desc, &is_null);

Re: plpython (triggers?) and dropped attributes

От:
"Arthur Ward" <award@dominionsciences.com>
Дата:
> "Arthur Ward"  writes:
>> I have a table with a plpython trigger defined on it in 7.3.4. I've
>> dropped a column from that table, and now I cannot get a plpython
>> trigger
>> to run at all on that table.
>
> Would you try the attached patch?

Lightly tested, but it seems to be working. Thanks a bunch!
FAQ