Try ERPNext Buy Support Partners Foundation

Can't save item when using a linked image

I recently have trouble with picture I want to attach to Items, when I use a weblink:

this is the error message I am getting. Can’t make much if it though. It seems tat when I return the attachment (without clearing the image field) the image kind of remains visible in the Item.

Can anyone point me into the right direction?

Installed Apps

ERPNext: v11.1.71 (version-11)
Frappe Framework: v11.1.63 (version-11)

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/save.py", line 22, in savedocs
    doc.save()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 260, in save
    return self._save(*args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 296, in _save
    self.run_before_save_methods()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 876, in run_before_save_methods
    self.run_method("validate")
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 772, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 1048, in composer
    return composed(self, method, *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 1031, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 766, in <lambda>
    fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/stock/doctype/item/item.py", line 120, in validate
    self.make_thumbnail()
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/stock/doctype/item/item.py", line 273, in make_thumbnail
    file_doc.make_thumbnail()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/file/file.py", line 201, in make_thumbnail
    image, filename, extn = get_web_image(self.file_url)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/file/file.py", line 409, in get_web_image
    image = Image.open(StringIO(frappe.safe_decode(r.content)))
TypeError: initial_value must be str or None, not bytes

Traceback (most recent call last):
  File "/home/frappe/frappe-bench/apps/frappe/frappe/app.py", line 61, in application
    response = frappe.handler.handle()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 21, in handle
    data = execute_cmd(cmd)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/handler.py", line 56, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/__init__.py", line 1036, in call
    return fn(*args, **newargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/desk/form/save.py", line 22, in savedocs
    doc.save()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 260, in save
    return self._save(*args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 296, in _save
    self.run_before_save_methods()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 876, in run_before_save_methods
    self.run_method("validate")
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 772, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 1048, in composer
    return composed(self, method, *args, **kwargs)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 1031, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py", line 766, in <lambda>
    fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/stock/doctype/item/item.py", line 120, in validate
    self.make_thumbnail()
  File "/home/frappe/frappe-bench/apps/erpnext/erpnext/stock/doctype/item/item.py", line 273, in make_thumbnail
    file_
doc.make_thumbnail()
  File "/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/file/file.py", line 201, in make_thumbnail
    image, filename, extn = get_web_image(self.file_url)
  File "/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/file/file.py", line 409, in get_web_image
    image = Image.open(StringIO(frappe.safe_decode(r.content)))
TypeError: initial_value must be str or None, not bytes

Hi maybe change StringIO to BytesIO as this suggests:

Do I understand you correctly if I assume this would be a suggestion on how to change the ERPNext core Code in order to not run into this problem? If so, I’d need some support on proposing such a change due to lack of insight into python in general and the core code in particular.

If it’s a possible solution a regular ERPNext user can apply I am not quite getting what such a user practically can do.

Yes that’s the idea - provided this code change fixes your problem, the Frappe
maintainers may want a pull request to fix this in the core?

ok, I’ll try get an issue glued together on this. Even though I am afraid it won’t be more then a bug report with a hint about where a solution may be found.

There must be many others facing this.

So this has already been reported https://github.com/frappe/frappe/issues/7318

Hello @hrwx can you perhaps advise?

1 Like

you’re the best. Sorry for not finding that myself.

No worry not a problem @vrms