From 92ea0c6f6c12d8511b8c3221ffa33904993ef00c Mon Sep 17 00:00:00 2001 From: amercader Date: Sun, 9 Dec 2018 23:32:57 +0100 Subject: [PATCH] Return message from Postgres when there's a validation during import Right now when there's a validation error during datastore_create you just get a generic message with no actual details (eg wrong type or wrong values). At least let's return Postgres message which gives the column and/or the wrong value. --- ckanext/datastore/backend/postgres.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/ckanext/datastore/backend/postgres.py b/ckanext/datastore/backend/postgres.py index af04d9374fa..b6c6460ef5c 100644 --- a/ckanext/datastore/backend/postgres.py +++ b/ckanext/datastore/backend/postgres.py @@ -1054,11 +1054,10 @@ def upsert_data(context, data_dict): try: context['connection'].execute(sql_string, rows) - except sqlalchemy.exc.DataError: + except sqlalchemy.exc.DataError as err: raise InvalidDataError( - toolkit._("The data was invalid (for example: a numeric value " - "is out of range or was inserted into a text field)." - )) + toolkit._("The data was invalid: {}" + ).format(_programming_error_summary(err))) except sqlalchemy.exc.DatabaseError as err: raise ValidationError( {u'records': [_programming_error_summary(err)]})