diff options
| author | Devendra Kavthekar <dek@odoo.com> | 2016-07-22 19:04:12 +0530 |
|---|---|---|
| committer | Yannick Tivisse <yti@odoo.com> | 2016-11-17 16:33:57 +0100 |
| commit | 8872800e757ee80496daf054341fb85894f30b53 (patch) | |
| tree | b38051b34499d8fb854bdb5f4a898b470f783218 /odoo/sql_db.py | |
| parent | 34a52585341a929b8b4962da1a7a2f412fe36a2b (diff) | |
[IMP] sql_db: Improve error message logging on database querries
Purpose:
When we have a SQL error, it's not very easy to identify the root of the crash. For example if a mandatory field is not set on a row creation, it difficult to see which field isn't correctly set as a lot of fields are not required and a lot a NULL values are present in the INSERT querry.
Specification:
Show a proper log message, with the reason (cause) of the sql error.
Behavior Modification Examples:
Some sample log after applied fix. The new line are those beginning by '+'
2016-10-25 09:59:40,208 21161 INFO ent_master odoo.sql_db: bad query: INSERT INTO "res_partner_category" ("id", "active", "color", "create_uid", "write_uid", "create_date", "write_date") VALUES(nextval('res_partner_category_id_seq'), true, 10, 1, 1, (now() at time zone 'UTC'), (now() at time zone 'UTC')) RETURNING id
+REASON: null value in column "name" violates not-null constraint
+DETAIL: Failing row contains (27, null, null, 1, null, 10, 1, null, 2016-10-25 09:59:40.207202, t, 2016-10-25 09:59:40.207202).
2016-10-25 10:00:29,710 21161 INFO ent_master odoo.sql_db: bad query: UPDATE "res_partner" SET "parent_id"=1001,"type"='contact',"name"='Course Script',"company_name"=NULL,"write_uid"=1,"write_date"=(now() at time zone 'UTC') WHERE id IN (1)
+REASON: insert or update on table "res_partner" violates foreign key constraint "res_partner_parent_id_fkey"
+DETAIL: Key (parent_id)=(1001) is not present in table "res_partner".
2016-10-25 10:23:28,690 21336 INFO ent_master odoo.sql_db: bad query: DELETE FROM res_country WHERE id IN (235)
+REASON: null value in column "country_id" violates not-null constraint
+DETAIL: Failing row contains (9, 1, AL, Alabama, null, 1, 2016-10-24 10:19:58.765552, 2016-10-21 09:32:26.939607).
+CONTEXT: SQL statement "UPDATE ONLY "public"."res_country_state" SET "country_id" = NULL WHERE $1 OPERATOR(pg_catalog.=) "country_id""
Diffstat (limited to 'odoo/sql_db.py')
| -rw-r--r-- | odoo/sql_db.py | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/odoo/sql_db.py b/odoo/sql_db.py index f2b200225a2..a7c7d6fc54d 100644 --- a/odoo/sql_db.py +++ b/odoo/sql_db.py @@ -216,9 +216,9 @@ class Cursor(object): try: params = params or None res = self._obj.execute(query, params) - except Exception: + except Exception as e: if self._default_log_exceptions if log_exceptions is None else log_exceptions: - _logger.info("bad query: %s", self._obj.query or query) + _logger.info("bad query: %s \nERROR: %s", self._obj.query or query, e) raise # simple query count is always computed |
