From 5f34983f0bbf77945567a3be7aace0798b62e634 Mon Sep 17 00:00:00 2001 From: "Jay (Open ERP)" Date: Thu, 21 Jan 2010 20:28:07 +0530 Subject: [PATCH] [FIX] O2M should check existing relations for its concerned M2O lp bug: https://launchpad.net/bugs/456978 fixed bzr revid: jvo@tinyerp.com-20100121145807-ixlsuj3xakibd753 --- bin/osv/orm.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bin/osv/orm.py b/bin/osv/orm.py index 3f247b9831a..77bc161da65 100644 --- a/bin/osv/orm.py +++ b/bin/osv/orm.py @@ -1765,6 +1765,12 @@ class orm(orm_template): if isinstance(f, fields.one2many): cr.execute("SELECT relname FROM pg_class WHERE relkind='r' AND relname=%s", (f._obj,)) + + if self.pool.get(f._obj): + if f._fields_id not in self.pool.get(f._obj)._columns.keys(): + if not self.pool.get(f._obj)._inherits or (f._fields_id not in self.pool.get(f._obj)._inherit_fields.keys()): + raise except_orm('Programming Error', ("There is no reference field '%s' found for '%s'") % (f._fields_id,f._obj,)) + if cr.fetchone(): cr.execute("SELECT count(1) as c FROM pg_class c,pg_attribute a WHERE c.relname=%s AND a.attname=%s AND c.oid=a.attrelid", (f._obj, f._fields_id)) res = cr.fetchone()[0]