summaryrefslogtreecommitdiff
path: root/odoo/addons/test_impex/models.py
diff options
context:
space:
mode:
authorxmo-odoo <xmo@odoo.com>2017-04-11 14:51:53 +0200
committerGitHub <noreply@github.com>2017-04-11 14:51:53 +0200
commitca74b5e1c8a48bcdeb396625ec0d8028a5a9d5f1 (patch)
tree80c175e553f62ff6696272e96019c5d64f7fae5f /odoo/addons/test_impex/models.py
parenta8994b40754834b62038fcc0540cad766ac9e278 (diff)
[IMP] convert PG errors through pg93 diag info
Previously availability of meta-information (failing constraint, impacted table and column, …) in pg errors (e.g. constraint check failure) was limited and only available through formatted error messages, which could be localised (by PG itself) so not did getting that information require string extraction it was brittle in the face of localised instances. Postgres 9.3 adds this meta-information to error diagnostic data (`PQresultErrorField`), allowing easy programmatic access to it. Psycopg2 [added a Diagnostic object](http://initd.org/psycopg/docs/extensions.html#psycopg2.extensions.Diagnostics) around the time pg9.3 was itself released. Assuming Odoo now requires pg >= 9.3 we can remove the old string munging extraction for diagnostic. * funny story, the handling of 23505 didn't actually work because "duplicate key value violates unique constraint" is a literal part of the error message, I'd misunderstood "value" as a field name because my test model's field was called "value". Makes sense too since you can set UNIQUE constraints on multiple fields (and UNIQUE indices on expressions) * for both errors, it should be possible to use the table_name or constraint metadata to provide messages about sub-model issues (a constraint on an m2o), but that's not currently handled Fixes #15323
Diffstat (limited to 'odoo/addons/test_impex/models.py')
-rw-r--r--odoo/addons/test_impex/models.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/odoo/addons/test_impex/models.py b/odoo/addons/test_impex/models.py
index 9dc1f6b31ed..f1e10b10abf 100644
--- a/odoo/addons/test_impex/models.py
+++ b/odoo/addons/test_impex/models.py
@@ -3,6 +3,7 @@
from odoo import api, fields, models
+
def selection_fn(model):
return [(str(key), val) for key, val in enumerate(["Corge", "Grault", "Wheee", "Moog"])]
@@ -148,7 +149,10 @@ class OnlyOne(models.Model):
_name = 'export.unique'
value = fields.Integer()
+ value2 = fields.Integer()
+ value3 = fields.Integer()
_sql_constraints = [
('value_unique', 'unique (value)', "The value must be unique"),
+ ('pair_unique', 'unique (value2, value3)', "The values must be unique"),
]