Chris Biersbach (OpenERP) has proposed merging 
lp:~openerp-dev/openobject-addons/6.1-opw-581240-cbi into 
lp:openobject-addons/6.1.

Requested reviews:
  OpenERP Core Team (openerp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/6.1-opw-581240-cbi/+merge/138680

The issue: When trying to generate accounting reports, an error is thrown 
because the sql query parser stack overflows

The reason: There are too many accounts, thus when getting all of the children, 
the query becomes too long

The fix: I split the accounts into chunks of a predetermined size and do one 
query per chunk, causing the stack to no longer overflow
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/6.1-opw-581240-cbi/+merge/138680
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/6.1-opw-581240-cbi.
=== modified file 'account/account.py'
--- account/account.py	2012-10-09 09:58:14 +0000
+++ account/account.py	2012-12-07 10:12:24 +0000
@@ -250,7 +250,14 @@
 
     def _get_children_and_consol(self, cr, uid, ids, context=None):
         #this function search for all the children and all consolidated children (recursively) of the given account ids
-        ids2 = self.search(cr, uid, [('parent_id', 'child_of', ids)], context=context)
+        # we split the ids into several chunks, because if there are too many at once, this can cause the sql query parser stack to overflow
+        if not isinstance(ids, (list, tuple)):
+            ids = [ids]
+        chunk_size = 100
+        ids_split = [ids[i:i + chunk_size] for i in range(0, len(ids), chunk_size)]
+        ids2 = []
+        for chunk in ids_split:
+            ids2.extend(self.search(cr, uid, [('parent_id', 'child_of', chunk)], context=context))
         ids3 = []
         for rec in self.browse(cr, uid, ids2, context=context):
             for child in rec.child_consol_ids:

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : openerp-dev-gtk@lists.launchpad.net
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to