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

Commit418df3a

Browse files
committed
Also save the error detail in SPIError
The temporarily broken plpython_unicode test shows a case where thisis used.Do remaining fix-ups on the expected files at the same time.
1 parentddf8c16 commit418df3a

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ SELECT * FROM unicode_test;
4141
SELECT unicode_plan1();
4242
WARNING: PL/Python: plpy.Error: unrecognized error in PLy_spi_execute_plan
4343
CONTEXT: PL/Python function "unicode_plan1"
44-
ERROR: PL/Python: could not convert Python Unicode object to PostgreSQL server encoding
44+
ERROR: PL/Python:plpy.SPIError: PL/Python:could not convert Python Unicode object to PostgreSQL server encoding
4545
DETAIL: UnicodeError: ASCII encoding error: ordinal not in range(128)
4646
CONTEXT: PL/Python function "unicode_plan1"
4747
SELECT unicode_plan2();

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ SELECT unicode_plan1();
4242
WARNING: PL/Python: plpy.Error: unrecognized error in PLy_spi_execute_plan
4343
CONTEXT: PL/Python function "unicode_plan1"
4444
ERROR: PL/Python: plpy.SPIError: PL/Python: could not convert Python Unicode object to PostgreSQL server encoding
45+
DETAIL: UnicodeEncodeError: 'ascii' codec can't encode character u'\x80' in position 0: ordinal not in range(128)
4546
CONTEXT: PL/Python function "unicode_plan1"
4647
SELECT unicode_plan2();
4748
unicode_plan2

‎src/pl/plpython/plpython.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ static char *PLy_procedure_name(PLyProcedure *);
294294
staticvoid
295295
PLy_elog(int,constchar*,...)
296296
__attribute__((format(printf,2,3)));
297-
staticvoidPLy_get_spi_error_data(PyObject*exc,char**hint,char**query,int*position);
297+
staticvoidPLy_get_spi_error_data(PyObject*exc,char**detail,char**hint,char**query,int*position);
298298
staticchar*PLy_traceback(int*);
299299

300300
staticvoid*PLy_malloc(size_t);
@@ -3551,7 +3551,7 @@ PLy_spi_exception_set(ErrorData *edata)
35513551
if (!spierror)
35523552
gotofailure;
35533553

3554-
spidata=Py_BuildValue("(zzi)",edata->hint,
3554+
spidata=Py_BuildValue("(zzzi)",edata->detail,edata->hint,
35553555
edata->internalquery,edata->internalpos);
35563556
if (!spidata)
35573557
gotofailure;
@@ -3586,13 +3586,14 @@ PLy_elog(int elevel, const char *fmt,...)
35863586
intxlevel;
35873587
StringInfoDataemsg;
35883588
PyObject*exc,*val,*tb;
3589+
char*detail=NULL;
35893590
char*hint=NULL;
35903591
char*query=NULL;
35913592
intposition=0;
35923593

35933594
PyErr_Fetch(&exc,&val,&tb);
35943595
if (exc!=NULL&&PyErr_GivenExceptionMatches(val,PLy_exc_spi_error))
3595-
PLy_get_spi_error_data(val,&hint,&query,&position);
3596+
PLy_get_spi_error_data(val,&detail,&hint,&query,&position);
35963597
PyErr_Restore(exc,val,tb);
35973598

35983599
xmsg=PLy_traceback(&xlevel);
@@ -3626,6 +3627,7 @@ PLy_elog(int elevel, const char *fmt,...)
36263627
else
36273628
ereport(elevel,
36283629
(errmsg("PL/Python: %s",xmsg),
3630+
(detail) ?errdetail("%s",detail) :0,
36293631
(hint) ?errhint("%s",hint) :0,
36303632
(query) ?internalerrquery(query) :0,
36313633
(position) ?internalerrposition(position) :0));
@@ -3650,15 +3652,15 @@ PLy_elog(int elevel, const char *fmt,...)
36503652
* Extract the error data from a SPIError
36513653
*/
36523654
staticvoid
3653-
PLy_get_spi_error_data(PyObject*exc,char**hint,char**query,int*position)
3655+
PLy_get_spi_error_data(PyObject*exc,char**detail,char**hint,char**query,int*position)
36543656
{
36553657
PyObject*spidata=NULL;
36563658

36573659
spidata=PyObject_GetAttrString(exc,"spidata");
36583660
if (!spidata)
36593661
gotocleanup;
36603662

3661-
if (!PyArg_ParseTuple(spidata,"zzi",hint,query,position))
3663+
if (!PyArg_ParseTuple(spidata,"zzzi",detail,hint,query,position))
36623664
gotocleanup;
36633665

36643666
cleanup:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp