Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6f49703

Browse files
committed
Clean up plpython error reporting so that its regression test passes
with some amount of cleanliness. I see no need to report the internal Python name rather than the SQL procedure name in error tracebacks.
1 parent 9d00798 commit 6f49703

File tree

3 files changed

+41
-31
lines changed

3 files changed

+41
-31
lines changed

src/pl/plpython/error.expected

+17-14
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,36 @@
11
SELECT invalid_type_uncaught('rick');
2-
WARNING: plpython: in function __plpython_procedure_invalid_type_uncaught_49801:
3-
plpy.SPIError: Cache lookup for type `test' failed.
2+
WARNING: plpython: in function invalid_type_uncaught:
3+
plpy.SPIError: Unknown error in PLy_spi_prepare.
4+
ERROR: Type "test" does not exist
45
SELECT invalid_type_caught('rick');
5-
WARNING: plpython: in function __plpython_procedure_invalid_type_caught_49802:
6-
plpy.SPIError: Cache lookup for type `test' failed.
6+
WARNING: plpython: in function invalid_type_caught:
7+
plpy.SPIError: Unknown error in PLy_spi_prepare.
8+
ERROR: Type "test" does not exist
79
SELECT invalid_type_reraised('rick');
8-
WARNING: plpython: in function __plpython_procedure_invalid_type_reraised_49803:
9-
plpy.SPIError: Cache lookup for type `test' failed.
10+
WARNING: plpython: in function invalid_type_reraised:
11+
plpy.SPIError: Unknown error in PLy_spi_prepare.
12+
ERROR: Type "test" does not exist
1013
SELECT valid_type('rick');
1114
valid_type
1215
------------
1316

1417
(1 row)
1518

1619
SELECT read_file('/etc/passwd');
17-
ERROR: plpython: Call of function `__plpython_procedure_read_file_49809' failed.
20+
ERROR: plpython: Call of function `read_file' failed.
1821
exceptions.IOError: can't open files in restricted mode
1922
SELECT write_file('/tmp/plpython','This is very bad');
20-
ERROR: plpython: Call of function `__plpython_procedure_write_file_49810' failed.
23+
ERROR: plpython: Call of function `write_file' failed.
2124
exceptions.IOError: can't open files in restricted mode
2225
SELECT getpid();
23-
ERROR: plpython: Call of function `__plpython_procedure_getpid_49811' failed.
24-
exceptions.AttributeError: getpid
26+
ERROR: plpython: Call of function `getpid' failed.
27+
exceptions.AttributeError: 'module' object has no attribute 'getpid'
2528
SELECT uname();
26-
ERROR: plpython: Call of function `__plpython_procedure_uname_49812' failed.
27-
exceptions.AttributeError: uname
29+
ERROR: plpython: Call of function `uname' failed.
30+
exceptions.AttributeError: 'module' object has no attribute 'uname'
2831
SELECT sys_exit();
29-
ERROR: plpython: Call of function `__plpython_procedure_sys_exit_49813' failed.
30-
exceptions.AttributeError: exit
32+
ERROR: plpython: Call of function `sys_exit' failed.
33+
exceptions.AttributeError: 'module' object has no attribute 'exit'
3134
SELECT sys_argv();
3235
sys_argv
3336
----------------

src/pl/plpython/plpython.c

+17-9
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
3030
*
3131
* IDENTIFICATION
32-
* $Header: /cvsroot/pgsql/src/pl/plpython/plpython.c,v 1.27 2002/11/22 16:25:30 tgl Exp $
32+
* $Header: /cvsroot/pgsql/src/pl/plpython/plpython.c,v 1.28 2003/01/31 22:25:13 tgl Exp $
3333
*
3434
*********************************************************************
3535
*/
@@ -127,7 +127,8 @@ typedef struct PLyTypeInfo
127127
*/
128128
typedef struct PLyProcedure
129129
{
130-
char *proname;
130+
char *proname; /* SQL name of procedure */
131+
char *pyname; /* Python name of procedure */
131132
TransactionId fn_xmin;
132133
CommandId fn_cmin;
133134
PLyTypeInfo result; /* also used to store info for trigger
@@ -1050,7 +1051,7 @@ static PLyProcedure *
10501051
PLy_procedure_create(FunctionCallInfo fcinfo, bool is_trigger,
10511052
HeapTuple procTup, char *key)
10521053
{
1053-
char procName[256];
1054+
char procName[NAMEDATALEN+256];
10541055

10551056
DECLARE_EXC();
10561057
Form_pg_proc procStruct;
@@ -1073,8 +1074,10 @@ PLy_procedure_create(FunctionCallInfo fcinfo, bool is_trigger,
10731074
elog(FATAL, "plpython: Procedure name would overrun buffer");
10741075

10751076
proc = PLy_malloc(sizeof(PLyProcedure));
1076-
proc->proname = PLy_malloc(strlen(procName) + 1);
1077-
strcpy(proc->proname, procName);
1077+
proc->proname = PLy_malloc(strlen(NameStr(procStruct->proname)) + 1);
1078+
strcpy(proc->proname, NameStr(procStruct->proname));
1079+
proc->pyname = PLy_malloc(strlen(procName) + 1);
1080+
strcpy(proc->pyname, procName);
10781081
proc->fn_xmin = HeapTupleHeaderGetXmin(procTup->t_data);
10791082
proc->fn_cmin = HeapTupleHeaderGetCmin(procTup->t_data);
10801083
PLy_typeinfo_init(&proc->result);
@@ -1235,21 +1238,21 @@ PLy_procedure_compile(PLyProcedure * proc, const char *src)
12351238
/*
12361239
* insert the function code into the interpreter
12371240
*/
1238-
msrc = PLy_procedure_munge_source(proc->proname, src);
1241+
msrc = PLy_procedure_munge_source(proc->pyname, src);
12391242
crv = PyObject_CallMethod(proc->interp, "r_exec", "s", msrc);
12401243
free(msrc);
12411244

12421245
if ((crv != NULL) && (!PyErr_Occurred()))
12431246
{
12441247
int clen;
1245-
char call[256];
1248+
char call[NAMEDATALEN+256];
12461249

12471250
Py_DECREF(crv);
12481251

12491252
/*
12501253
* compile a call to the function
12511254
*/
1252-
clen = snprintf(call, sizeof(call), "%s()", proc->proname);
1255+
clen = snprintf(call, sizeof(call), "%s()", proc->pyname);
12531256
if ((clen < 0) || (clen >= sizeof(call)))
12541257
elog(ERROR, "plpython: string would overflow buffer.");
12551258
proc->code = Py_CompileString(call, "<string>", Py_eval_input);
@@ -1321,6 +1324,8 @@ PLy_procedure_delete(PLyProcedure * proc)
13211324
Py_XDECREF(proc->me);
13221325
if (proc->proname)
13231326
PLy_free(proc->proname);
1327+
if (proc->pyname)
1328+
PLy_free(proc->pyname);
13241329
for (i = 0; i < proc->nargs; i++)
13251330
if (proc->args[i].is_rel == 1)
13261331
{
@@ -2748,9 +2753,12 @@ PLy_output(volatile int level, PyObject * self, PyObject * args)
27482753
}
27492754

27502755

2751-
/* Get the last procedure name called by the backend ( the innermost,
2756+
/*
2757+
* Get the last procedure name called by the backend ( the innermost,
27522758
* If a plpython procedure call calls the backend and the backend calls
27532759
* another plpython procedure )
2760+
*
2761+
* NB: this returns SQL name, not the internal Python procedure name
27542762
*/
27552763

27562764
char *

src/pl/plpython/test.sh

+7-8
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,18 @@ echo -n "*** Running error handling tests."
3030
psql -q -e $DBNAME < plpython_error.sql > error.output 2>&1
3131
echo " Done. ***"
3232

33-
echo -n "*** Checking the results of the feature tests"
34-
if diff -u feature.expected feature.output > feature.diff 2>&1 ; then
33+
echo -n "*** Checking the results of the feature tests."
34+
if diff -c feature.expected feature.output > feature.diff 2>&1 ; then
3535
echo -n " passed!"
3636
else
3737
echo -n " failed! Please examine feature.diff."
3838
fi
3939
echo " Done. ***"
4040

4141
echo -n "*** Checking the results of the error handling tests."
42-
diff -u error.expected error.output > error.diff 2>&1
42+
if diff -c error.expected error.output > error.diff 2>&1 ; then
43+
echo -n " passed!"
44+
else
45+
echo -n " failed! Please examine error.diff."
46+
fi
4347
echo " Done. ***"
44-
echo "*** You need to check the file error.diff and make sure that"
45-
echo " any differences are due only to the oid encoded in the "
46-
echo " python function name. ***"
47-
48-
# or write a fancier error checker...

0 commit comments

Comments
 (0)