From 330a3ff6ea8e9c87a9a504cb5cc667f27957c072 Mon Sep 17 00:00:00 2001
From: Raphael Collet <rco@openerp.com>
Date: Wed, 24 Sep 2014 15:41:09 +0200
Subject: [PATCH] [IMP] models: when checking for data in a table, do not use
 column 'id'

Replace the query "SELECT min(id) FROM xxx" by "SELECT 1 FROM xxx LIMIT 1".
Both requests are as efficient, and the second one does not crash if column
'id' is missing.
---
 openerp/models.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/openerp/models.py b/openerp/models.py
index 360c2208d740..4f9fc2852829 100644
--- a/openerp/models.py
+++ b/openerp/models.py
@@ -2502,8 +2502,8 @@ class BaseModel(object):
                 self._create_table(cr)
                 has_rows = False
             else:
-                cr.execute('SELECT min(id) FROM "%s"' % (self._table,))
-                has_rows = cr.fetchone()[0] is not None
+                cr.execute('SELECT 1 FROM "%s" LIMIT 1' % self._table)
+                has_rows = cr.rowcount
 
             cr.commit()
             if self._parent_store:
-- 
GitLab