Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3a4a33a

Browse files
committed
PL/Python: Report argument parsing errors using exceptions
Instead of calling PLy_elog() for reporting Python argument parsingerrors, generate appropriate exceptions. This matches the existing plpyfunctions and is more consistent with the behavior of the Pythonargument parsing routines.
1 parent420c166 commit3a4a33a

File tree

2 files changed

+38
-13
lines changed

2 files changed

+38
-13
lines changed

‎src/pl/plpython/expected/plpython_ereport.out

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,29 @@ INFO: other types
5656
DETAIL: ['apple', 'orange', 'apple', 'pear', 'orange', 'banana']
5757
-- should fail
5858
DO $$ plpy.info('wrong sqlstate', sqlstate='54444A') $$ LANGUAGE plpythonu;
59-
ERROR: invalid SQLSTATE code
60-
CONTEXT: PL/Python anonymous code block
59+
ERROR: ValueError: invalid SQLSTATE code
60+
CONTEXT: Traceback (most recent call last):
61+
PL/Python anonymous code block, line 1, in <module>
62+
plpy.info('wrong sqlstate', sqlstate='54444A')
63+
PL/Python anonymous code block
6164
DO $$ plpy.info('unsupported argument', blabla='fooboo') $$ LANGUAGE plpythonu;
62-
ERROR: 'blabla' is an invalid keyword argument for this function
63-
CONTEXT: PL/Python anonymous code block
65+
ERROR: TypeError: 'blabla' is an invalid keyword argument for this function
66+
CONTEXT: Traceback (most recent call last):
67+
PL/Python anonymous code block, line 1, in <module>
68+
plpy.info('unsupported argument', blabla='fooboo')
69+
PL/Python anonymous code block
6470
DO $$ plpy.info('first message', message='second message') $$ LANGUAGE plpythonu;
65-
ERROR: the message is already specified
66-
CONTEXT: PL/Python anonymous code block
71+
ERROR: TypeError: Argument 'message' given by name and position
72+
CONTEXT: Traceback (most recent call last):
73+
PL/Python anonymous code block, line 1, in <module>
74+
plpy.info('first message', message='second message')
75+
PL/Python anonymous code block
6776
DO $$ plpy.info('first message', 'second message', message='third message') $$ LANGUAGE plpythonu;
68-
ERROR: the message is already specified
69-
CONTEXT: PL/Python anonymous code block
77+
ERROR: TypeError: Argument 'message' given by name and position
78+
CONTEXT: Traceback (most recent call last):
79+
PL/Python anonymous code block, line 1, in <module>
80+
plpy.info('first message', 'second message', message='third message')
81+
PL/Python anonymous code block
7082
-- raise exception in python, handle exception in plgsql
7183
CREATE OR REPLACE FUNCTION raise_exception(_message text, _detail text DEFAULT NULL, _hint text DEFAULT NULL,
7284
_sqlstate text DEFAULT NULL,

‎src/pl/plpython/plpy_plpymodule.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,10 @@ PLy_output(volatile int level, PyObject *self, PyObject *args, PyObject *kw)
444444
{
445445
/* the message should not be overwriten */
446446
if (PyTuple_Size(args)!=0)
447-
PLy_elog(ERROR,"the message is already specified");
447+
{
448+
PLy_exception_set(PyExc_TypeError,"Argument 'message' given by name and position");
449+
returnNULL;
450+
}
448451

449452
if (message)
450453
pfree(message);
@@ -467,18 +470,28 @@ PLy_output(volatile int level, PyObject *self, PyObject *args, PyObject *kw)
467470
elseif (strcmp(keyword,"constraint_name")==0)
468471
constraint_name=object_to_string(value);
469472
else
470-
PLy_elog(ERROR,"'%s' is an invalid keyword argument for this function",
471-
keyword);
473+
{
474+
PLy_exception_set(PyExc_TypeError,
475+
"'%s' is an invalid keyword argument for this function",
476+
keyword);
477+
returnNULL;
478+
}
472479
}
473480
}
474481

475482
if (sqlstatestr!=NULL)
476483
{
477484
if (strlen(sqlstatestr)!=5)
478-
PLy_elog(ERROR,"invalid SQLSTATE code");
485+
{
486+
PLy_exception_set(PyExc_ValueError,"invalid SQLSTATE code");
487+
returnNULL;
488+
}
479489

480490
if (strspn(sqlstatestr,"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ")!=5)
481-
PLy_elog(ERROR,"invalid SQLSTATE code");
491+
{
492+
PLy_exception_set(PyExc_ValueError,"invalid SQLSTATE code");
493+
returnNULL;
494+
}
482495

483496
sqlstate=MAKE_SQLSTATE(sqlstatestr[0],
484497
sqlstatestr[1],

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp