Skip to Content
Menu
This question has been flagged

Hi

So I was developing a module that exports every products barcode and image to an Excel, and that then returns the an Excel file. This works fine when there's just a couple pictures, but when I tried running the method on a bigger db with tons more pictures I got an error.

Here is the code that's being run:

class ExportProductImage(models.TransientModel):
_name = "export.product.image"
_description = "Export product image"
datas = fields.Binary('File', readonly=True)
datas_fname = fields.Char('Filename', readonly=True)
def generate_excel_product_image(self):
filename = 'product_images'
fp = BytesIO()
book = xlsxwriter.Workbook(fp)
sheet1 = book.add_worksheet("Afbeeldingen")
sheet1.set_landscape()
sheet1.set_default_row(230)
sheet1.set_column('B:B', 73)
sheet1.set_row(0, 20)
sheet1.write('A1', 'Barcode')
sheet1.write('B1', 'Afbeelding')
product_templates = self.env['product.template'].search([]) # image_1920
row = 2
for temp in product_templates:
if temp.image_1024:
sheet1.write('A'+str(row), "'" + str(temp.barcode))
image = BytesIO(base64.b64decode(temp.image_1024))
sheet1.insert_image('B' + str(row), "img" + str(row), {'x_scale': 0.5, 'y_scale': 0.5, 'image_data': image, 'object_position': 1})
row += 1
book.close()
out = base64.encodestring(fp.getvalue())
self.write({'datas': out, 'datas_fname': filename})
fp.close()
filename += '%2Exlsx'
return {
'type': 'ir.actions.act_url',
'target': 'new',
'url': 'web/content/?model=' + self._name + '&id=' + str(
self.id) + '&field=datas&download=true&filename=' + filename,
}



Here is the traceback:

Fout:
Odoo Server Error

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 225, in execute
    res = self._obj.execute(query, params)
psycopg2.OperationalError: cannot allocate memory for output buffer


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/odoo/loglevels.py", line 92, in ustr
    return text_type(value)
MemoryError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 656, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 314, in _handle_exception
    raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
  File "/usr/lib/python3/dist-packages/odoo/tools/pycompat.py", line 87, in reraise
    raise value
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 698, in dispatch
    result = self._call_function(**self.params)
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 346, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/odoo/service/model.py", line 97, in wrapper
    return f(dbname, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 339, in checked_call
    result = self.endpoint(*a, **kw)
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 941, in __call__
    return self.method(*args, **kw)
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 519, in response_wrap
    response = f(*args, **kw)
  File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 966, in call_button
    action = self._call_kw(model, method, args, {})
  File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 954, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "/usr/lib/python3/dist-packages/odoo/api.py", line 759, in call_kw
    return _call_kw_multi(method, model, args, kwargs)
  File "/usr/lib/python3/dist-packages/odoo/api.py", line 746, in _call_kw_multi
    result = method(recs, *args, **kwargs)
  File "/mnt/repo/custom/report_stock_wizard/wizard/export_image.py", line 42, in generate_excel_product_image
    self.write({'datas': out, 'datas_fname': filename})
  File "/usr/lib/python3/dist-packages/odoo/models.py", line 3324, in write
    self._write(store_vals)
  File "/usr/lib/python3/dist-packages/odoo/models.py", line 3417, in _write
    cr.execute(query, params + [sub_ids])
  File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 148, in wrapper
    return f(self, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/odoo/sql_db.py", line 228, in execute
    _logger.error("bad query: %s\nERROR: %s", ustr(self._obj.query or query), e)
  File "/usr/lib/python3/dist-packages/odoo/loglevels.py", line 94, in ustr
    raise UnicodeError('unable to convert %r' % (value,))
MemoryError


Anyone know how I could solve this?

For those wondering, these are in my config file:

limit_memory_hard = 2684354560
limit_memory_soft = 2147483648
limit_request = 8192
limit_time_cpu = 120
limit_time_real = 9999
limit_time_real_cron = -1
longpolling_port = 8072
max_cron_threads = 9
workers = 0


When I put more then 0 workers, I get a bus error so that's another problem.




Avatar
Discard
Related Posts Replies Views Activity
1
Dec 23
1944
1
Aug 23
2803
1
Jan 20
2553
1
Apr 22
1918
2
Sep 20
5079