From ae42652add3d9fa4aee64c2cb77fbde206ee87e4 Mon Sep 17 00:00:00 2001 From: Catalin Iacob Date: Mon, 29 Feb 2016 07:28:05 +0100 Subject: [PATCH 3/5] Pass message only as positional argument --- src/pl/plpython/expected/plpython_test.out | 14 +++++++------- src/pl/plpython/plpy_plpymodule.c | 4 +--- src/pl/plpython/sql/plpython_test.sql | 6 +++--- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/pl/plpython/expected/plpython_test.out b/src/pl/plpython/expected/plpython_test.out index 8a55ee2..83e4fc6 100644 --- a/src/pl/plpython/expected/plpython_test.out +++ b/src/pl/plpython/expected/plpython_test.out @@ -141,25 +141,25 @@ CREATE OR REPLACE FUNCTION raise_exception(_message text, _detail text DEFAULT N _schema text DEFAULT NULL, _table text DEFAULT NULL, _column text DEFAULT NULL, _datatype text DEFAULT NULL, _constraint text DEFAULT NULL) RETURNS void AS $$ -kwargs = { "message":_message, "detail":_detail, "hint":_hint, +kwargs = { "detail":_detail, "hint":_hint, "sqlstate":_sqlstate, "schema":_schema, "table":_table, "column":_column, "datatype":_datatype, "constraint":_constraint } # ignore None values -plpy.error(**dict((k, v) for k, v in iter(kwargs.items()) if v)) +plpy.error(_message, **dict((k, v) for k, v in iter(kwargs.items()) if v)) $$ LANGUAGE plpythonu; SELECT raise_exception('hello', 'world'); ERROR: plpy.Error: hello DETAIL: world CONTEXT: Traceback (most recent call last): PL/Python function "raise_exception", line 6, in - plpy.error(**dict((k, v) for k, v in iter(kwargs.items()) if v)) + plpy.error(_message, **dict((k, v) for k, v in iter(kwargs.items()) if v)) PL/Python function "raise_exception" SELECT raise_exception('message text', 'detail text', _sqlstate => 'YY333'); ERROR: plpy.Error: message text DETAIL: detail text CONTEXT: Traceback (most recent call last): PL/Python function "raise_exception", line 6, in - plpy.error(**dict((k, v) for k, v in iter(kwargs.items()) if v)) + plpy.error(_message, **dict((k, v) for k, v in iter(kwargs.items()) if v)) PL/Python function "raise_exception" SELECT raise_exception(_message => 'message text', _detail => 'detail text', @@ -175,7 +175,7 @@ DETAIL: detail text HINT: hint text CONTEXT: Traceback (most recent call last): PL/Python function "raise_exception", line 6, in - plpy.error(**dict((k, v) for k, v in iter(kwargs.items()) if v)) + plpy.error(_message, **dict((k, v) for k, v in iter(kwargs.items()) if v)) PL/Python function "raise_exception" SELECT raise_exception(_message => 'message text', _hint => 'hint text', @@ -186,7 +186,7 @@ ERROR: plpy.Error: message text HINT: hint text CONTEXT: Traceback (most recent call last): PL/Python function "raise_exception", line 6, in - plpy.error(**dict((k, v) for k, v in iter(kwargs.items()) if v)) + plpy.error(_message, **dict((k, v) for k, v in iter(kwargs.items()) if v)) PL/Python function "raise_exception" DO $$ DECLARE @@ -245,7 +245,7 @@ ERROR: plpy.SPIError: plpy.Error: my message HINT: some hint do $$ try: - plpy.error(message = 'my message', sqlstate = 'XX987', hint = 'some hint', table = 'users_tab', datatype = 'user_type') + plpy.error('my message', sqlstate = 'XX987', hint = 'some hint', table = 'users_tab', datatype = 'user_type') except Exception, e: plpy.info('sqlstate: %s, hint: %s, tablename: %s, datatype: %s' % (e.sqlstate, e.hint, e.table_name, e.datatype_name)) raise e diff --git a/src/pl/plpython/plpy_plpymodule.c b/src/pl/plpython/plpy_plpymodule.c index 0ad8611..6573778 100644 --- a/src/pl/plpython/plpy_plpymodule.c +++ b/src/pl/plpython/plpy_plpymodule.c @@ -438,9 +438,7 @@ PLy_output(volatile int level, PyObject *self, PyObject *args, PyObject *kw) { char *keyword = PyString_AsString(key); - if (strcmp(keyword, "message") == 0) - message = object_to_string(value); - else if (strcmp(keyword, "detail") == 0) + if (strcmp(keyword, "detail") == 0) detail = object_to_string(value); else if (strcmp(keyword, "hint") == 0) hint = object_to_string(value); diff --git a/src/pl/plpython/sql/plpython_test.sql b/src/pl/plpython/sql/plpython_test.sql index 9bbeb34..d56a635 100644 --- a/src/pl/plpython/sql/plpython_test.sql +++ b/src/pl/plpython/sql/plpython_test.sql @@ -97,11 +97,11 @@ CREATE OR REPLACE FUNCTION raise_exception(_message text, _detail text DEFAULT N _schema text DEFAULT NULL, _table text DEFAULT NULL, _column text DEFAULT NULL, _datatype text DEFAULT NULL, _constraint text DEFAULT NULL) RETURNS void AS $$ -kwargs = { "message":_message, "detail":_detail, "hint":_hint, +kwargs = { "detail":_detail, "hint":_hint, "sqlstate":_sqlstate, "schema":_schema, "table":_table, "column":_column, "datatype":_datatype, "constraint":_constraint } # ignore None values -plpy.error(**dict((k, v) for k, v in iter(kwargs.items()) if v)) +plpy.error(_message, **dict((k, v) for k, v in iter(kwargs.items()) if v)) $$ LANGUAGE plpythonu; SELECT raise_exception('hello', 'world'); @@ -177,7 +177,7 @@ $$ LANGUAGE plpythonu; do $$ try: - plpy.error(message = 'my message', sqlstate = 'XX987', hint = 'some hint', table = 'users_tab', datatype = 'user_type') + plpy.error('my message', sqlstate = 'XX987', hint = 'some hint', table = 'users_tab', datatype = 'user_type') except Exception, e: plpy.info('sqlstate: %s, hint: %s, tablename: %s, datatype: %s' % (e.sqlstate, e.hint, e.table_name, e.datatype_name)) raise e -- 2.7.1