frappe / print_designer

Visual print designer for Frappe / ERPNext
GNU Affero General Public License v3.0
179 stars 101 forks source link

[HELP] Attaching File Error when generating PDF #263

Closed samy4sam closed 1 month ago

samy4sam commented 1 month ago

When I try to generate a PDF file from a Print Designer template, an Attaching File Error occurs.

I have two sites running on the same Frappe Docker installation. On one site I have no problems generating PDFs. On the other site I get this error:

Traceback with variables (most recent call last):
  File "apps/frappe/frappe/core/doctype/file/utils.py", line 358, in attach_files_to_document
    file.insert(ignore_permissions=True)
      doc = <PDPrintFormat: Offerte>
      event = 'on_update'
      attach_fields = [<Attach ImageDocField: print_designer_preview_img parent=Print Format>]
      df = <Attach ImageDocField: print_designer_preview_img parent=Print Format>
      value = '/private/files/print_designer-offerte-preview.jpg'
      unattached_file = None
      file = <File: unsaved>
  File "apps/frappe/frappe/model/document.py", line 285, in insert
    self.run_method("before_insert")
      self = <File: unsaved>
      ignore_permissions = True
      ignore_links = None
      ignore_if_duplicate = False
      ignore_mandatory = None
      set_name = None
      set_child_names = True
  File "apps/frappe/frappe/model/document.py", line 962, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
      self = <File: unsaved>
      method = 'before_insert'
      args = ()
      kwargs = {}
      fn = <function Document.run_method.<locals>.fn at 0x7f3ad7d03740>
  File "apps/frappe/frappe/model/document.py", line 1322, in composer
    return composed(self, method, *args, **kwargs)
      self = <File: unsaved>
      args = ()
      kwargs = {}
      hooks = []
      method = 'before_insert'
      doc_events = {'*': {'on_update': ['frappe.desk.notifications.clear_doctype_notifications', 'frappe.workflow.doctype.workflow_action.workflow_action.process_workflow_actions', 'frappe.core.doctype.file.utils.attach_files_to_document', 'frappe.automation.doctype.assignment_rule.assignment_rule.apply', 'frappe.automation.doctype.assignment_rule.assignment_rule.update_due_date', 'frappe.core.doctype.user_type.user_type.apply_permissions_for_non_standard_user_type'], 'after_rename': ['frappe.desk.notifications.clear_doctype_notifications'], 'on_cancel': ['frappe.desk.notifications.clear_doctype_notifications', 'frappe.workflow.doctype.workflow_action.workflow_action.process_workflow_actions', 'frappe.automation.doctype.assignment_rule.assignment_rule.apply'], 'on_trash': ['frappe.desk.notifications.clear_doctype_notifications', 'frappe.workflow.doctype.workflow_action.workflow_action.process_workflow_actions'], 'on_update_after_submit': ['frappe.workflow.doctype.workflow_action.workflow_action.process_w...
      composed = <function Document.hook.<locals>.compose.<locals>.runner at 0x7f3ad7d01760>
      compose = <function Document.hook.<locals>.compose at 0x7f3ad7d019e0>
      f = <function Document.run_method.<locals>.fn at 0x7f3ad7d03740>
  File "apps/frappe/frappe/model/document.py", line 1304, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
      self = <File: unsaved>
      method = 'before_insert'
      args = ()
      kwargs = {}
      add_to_return_value = <function Document.hook.<locals>.add_to_return_value at 0x7f3ad7d01bc0>
      fn = <function Document.run_method.<locals>.fn at 0x7f3ad7d03740>
      hooks = ()
  File "apps/frappe/frappe/model/document.py", line 959, in fn
    return method_object(*args, **kwargs)
      self = <File: unsaved>
      args = ()
      kwargs = {}
      method_object = <bound method File.before_insert of <File: unsaved>>
      method = 'before_insert'
  File "apps/frappe/frappe/core/doctype/file/file.py", line 103, in before_insert
    self.save_file(content=self.get_content())
      self = <File: unsaved>
  File "apps/frappe/frappe/core/doctype/file/file.py", line 534, in get_content
    with open(file_path, mode="rb") as f:
      self = <File: unsaved>
      file_path = './<MyURL>/private/files/print_designer-offerte-preview.jpg'
builtins.FileNotFoundError: [Errno 2] No such file or directory: './<MyURL>/private/files/print_designer-offerte-preview.jpg'

I have tried it with empty templates, but also with elements in them.

Any Ideas?

maharshivpatel commented 1 month ago

@samy4sam which version are you using ? you can ignore this error. underlying issue is something else.

few things to check:

do you have active internet connection ?

are you using jinja in your formats ?

are you using private images ? do you have access to them ?

samy4sam commented 1 month ago

@maharshivpatel Thanks for your fast reply!

ERPNext: v15.21.2 Frappe Framework: v15.25.0 Print Designer: v1.2.0

do you have active internet connection ? yes. I have the same problems on my mobile phone and also other team members are facing the same issue.

are you using jinja in your formats ? No

are you using private images ? do you have access to them ? No, I don't have private images

I copied the template from my second site, where it was working. Could that be a problem?

samy4sam commented 1 month ago

This is in the logs of the backend container:

ARNING Property: Unknown Property name. [64:2: word-wrap]
WARNING Property: Unknown Property name. [83:2: columns]
WARNING Property: Unknown Property name. [90:2: background-size]
WARNING Property: Unknown Property name. [98:2: object-fit]
WARNING Property: Unknown Property name. [110:2: -webkit-print-color-adjust]
WARNING Property: Unknown Property name. [158:2: word-break]
WARNING Property: Unknown Property name. [278:9: --scale-factor]
WARNING Property: Unknown Property name. [278:30: --modal-x]
WARNING Property: Unknown Property name. [278:46: --modal-y]
WARNING Property: Unknown Property name. [278:448: overflow-wrap]
WARNING Property: Unknown Property name. [278:496: user-select]
WARNING Property: Unknown Property name. [278:926: overflow-wrap]
WARNING Property: Unknown Property name. [278:974: user-select]
WARNING Property: Unknown Property name. [278:1384: user-select]
WARNING Property: Unknown Property name. [278:1490: user-select]
WARNING Property: Unknown Property name. [278:1874: user-select]
WARNING Property: Unknown Property name. [278:1893: object-fit]
WARNING Property: Unknown Property name. [278:1917: object-position]
WARNING Property: Unknown Property name. [278:1949: background-size]
WARNING Property: Unknown Property name. [278:2233: user-select]
WARNING Property: Unknown Property name. [278:2651: overflow-wrap]
WARNING Property: Unknown Property name. [278:2699: user-select]
WARNING Property: Unknown Property name. [278:3172: user-select]
WARNING Property: Unknown Property name. [278:3649: user-select]
WARNING Property: Unknown Property name. [278:3757: --print-width]
WARNING Property: Unknown Property name. [278:3783: --print-height]
WARNING Property: Unknown Property name. [278:3810: --print-container-width]
WARNING Property: Unknown Property name. [278:3846: --print-container-height]
WARNING Property: Unknown Property name. [278:3883: --print-margin-top]
WARNING Property: Unknown Property name. [278:3908: --print-margin-bottom]
WARNING Property: Unknown Property name. [278:3940: --print-margin-left]
WARNING Property: Unknown Property name. [278:3966: --print-margin-right]
WARNING Property: Unknown Property name. [278:4026: --print-width]
WARNING Property: Unknown Property name. [278:4052: --print-height]
WARNING Property: Unknown Property name. [278:4079: --print-container-width]
WARNING Property: Unknown Property name. [278:4115: --print-container-height]
WARNING Property: Unknown Property name. [278:4152: --print-margin-top]
WARNING Property: Unknown Property name. [278:4177: --print-margin-bottom]
WARNING Property: Unknown Property name. [278:4209: --print-margin-left]
WARNING Property: Unknown Property name. [278:4235: --print-margin-right]
WARNING Property: Unknown Property name. [278:4295: --print-width]
WARNING Property: Unknown Property name. [278:4321: --print-height]
WARNING Property: Unknown Property name. [278:4348: --print-container-width]
WARNING Property: Unknown Property name. [278:4384: --print-container-height]
WARNING Property: Unknown Property name. [278:4421: --print-margin-top]
WARNING Property: Unknown Property name. [278:4447: --print-margin-bottom]
WARNING Property: Unknown Property name. [278:4479: --print-margin-left]
WARNING Property: Unknown Property name. [278:4507: --print-margin-right]
WARNING Property: Unknown Property name. [284:9: dpi]
WARNING Property: Unknown Property name. [285:9: page-width]
WARNING Property: Unknown Property name. [286:9: page-height]
ERROR   Property: Invalid value for "CSS Level 2.1" property: -webkit-box [363:9: display]
ERROR   Property: Invalid value for "CSS Level 2.1" property: -webkit-flex [364:9: display]
ERROR   Property: Invalid value for "CSS Level 2.1" property: flex [365:9: display]
WARNING Property: Unknown Property name. [373:9: -webkit-box-sizing]
samy4sam commented 1 month ago

@maharshivpatel I tried it with another website on the same installation. I copied the template and it worked without any problems. I tried to find a difference between the two working sites and the non working site. I noticed that there is no encryption_key in site_config.json for the site that is not working.

maharshivpatel commented 1 month ago

@samy4sam i assume most likely issue is with your setup as it is working fine on other sites. i am closing this issue for now. if you face this issue on multiple setup please open new issue with error messages. Thank you.

samy4sam commented 1 month ago

@maharshivpatel I have dropped the site and set it up again. I have not yet made any changes in the default settings. To test the Print Designer, I created a sales order and wanted to generate a PDF from it. I still get this error message:

Traceback with variables (most recent call last):
  File "apps/frappe/frappe/core/doctype/file/utils.py", line 358, in attach_files_to_document
    file.insert(ignore_permissions=True)
      doc = <PDPrintFormat: Sales Order PD v2>
      event = 'on_update'
      attach_fields = [<Attach ImageDocField: print_designer_preview_img parent=Print Format>]
      df = <Attach ImageDocField: print_designer_preview_img parent=Print Format>
      value = '/private/files/print_designer-sales_order_pd_v2-preview6a56eb.jpg'
      unattached_file = None
      file = <File: unsaved>
  File "apps/frappe/frappe/model/document.py", line 285, in insert
    self.run_method("before_insert")
      self = <File: unsaved>
      ignore_permissions = True
      ignore_links = None
      ignore_if_duplicate = False
      ignore_mandatory = None
      set_name = None
      set_child_names = True
  File "apps/frappe/frappe/model/document.py", line 962, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
      self = <File: unsaved>
      method = 'before_insert'
      args = ()
      kwargs = {}
      fn = <function Document.run_method.<locals>.fn at 0x7f85933c6340>
  File "apps/frappe/frappe/model/document.py", line 1322, in composer
    return composed(self, method, *args, **kwargs)
      self = <File: unsaved>
      args = ()
      kwargs = {}
      hooks = []
      method = 'before_insert'
      doc_events = {'*': {'on_update': ['frappe.desk.notifications.clear_doctype_notifications', 'frappe.workflow.doctype.workflow_action.workflow_action.process_workflow_actions', 'frappe.core.doctype.file.utils.attach_files_to_document', 'frappe.automation.doctype.assignment_rule.assignment_rule.apply', 'frappe.automation.doctype.assignment_rule.assignment_rule.update_due_date', 'frappe.core.doctype.user_type.user_type.apply_permissions_for_non_standard_user_type'], 'after_rename': ['frappe.desk.notifications.clear_doctype_notifications'], 'on_cancel': ['frappe.desk.notifications.clear_doctype_notifications', 'frappe.workflow.doctype.workflow_action.workflow_action.process_workflow_actions', 'frappe.automation.doctype.assignment_rule.assignment_rule.apply'], 'on_trash': ['frappe.desk.notifications.clear_doctype_notifications', 'frappe.workflow.doctype.workflow_action.workflow_action.process_workflow_actions'], 'on_update_after_submit': ['frappe.workflow.doctype.workflow_action.workflow_action.process_w...
      composed = <function Document.hook.<locals>.compose.<locals>.runner at 0x7f85933c5e40>
      compose = <function Document.hook.<locals>.compose at 0x7f85933c6480>
      f = <function Document.run_method.<locals>.fn at 0x7f85933c6340>
  File "apps/frappe/frappe/model/document.py", line 1304, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
      self = <File: unsaved>
      method = 'before_insert'
      args = ()
      kwargs = {}
      add_to_return_value = <function Document.hook.<locals>.add_to_return_value at 0x7f85933c6160>
      fn = <function Document.run_method.<locals>.fn at 0x7f85933c6340>
      hooks = ()
  File "apps/frappe/frappe/model/document.py", line 959, in fn
    return method_object(*args, **kwargs)
      self = <File: unsaved>
      args = ()
      kwargs = {}
      method_object = <bound method File.before_insert of <File: unsaved>>
      method = 'before_insert'
  File "apps/frappe/frappe/core/doctype/file/file.py", line 103, in before_insert
    self.save_file(content=self.get_content())
      self = <File: unsaved>
  File "apps/frappe/frappe/core/doctype/file/file.py", line 534, in get_content
    with open(file_path, mode="rb") as f:
      self = <File: unsaved>
      file_path = './<MY_URL>/private/files/print_designer-sales_order_pd_v2-preview6a56eb.jpg'
builtins.FileNotFoundError: [Errno 2] No such file or directory: './<MY_URL>/private/files/print_designer-sales_order_pd_v2-preview6a56eb.jpg'

I would be very happy if you could help me or at least tell me what I can try to do to solve the problem.

maharshivpatel commented 1 month ago

@samy4sam can you change branch from main to develop if it is your local development setup.

samy4sam commented 1 month ago

@maharshivpatel I rebuilt the image with the develop branch of print_designer. After updating the services, I used bench --site <SITE> migrate to update the site states. I saw some patches of print_designer: Executing execute:from print_designer.patches.create_custom_fields import custom_field_patch; custom_field_patch() #208 in

But now I get this error on every site hosted in the stack:

Traceback with variables (most recent call last):
  File "apps/frappe/frappe/core/doctype/file/utils.py", line 358, in attach_files_to_document
    file.insert(ignore_permissions=True)
      doc = <PDPrintFormat: Ausgangsrechnung_V1>
      event = 'on_update'
      attach_fields = [<Attach ImageDocField: print_designer_preview_img parent=Print Format>]
      df = <Attach ImageDocField: print_designer_preview_img parent=Print Format>
      value = '/private/files/print_designer-ausgangsrechnung_v1-previewf5e512.jpg'
      unattached_file = None
      file = <File: unsaved>
  File "apps/frappe/frappe/model/document.py", line 285, in insert
    self.run_method("before_insert")
      self = <File: unsaved>
      ignore_permissions = True
      ignore_links = None
      ignore_if_duplicate = False
      ignore_mandatory = None
      set_name = None
      set_child_names = True
  File "apps/frappe/frappe/model/document.py", line 962, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
      self = <File: unsaved>
      method = 'before_insert'
      args = ()
      kwargs = {}
      fn = <function Document.run_method.<locals>.fn at 0x7f26f7a30ea0>
  File "apps/frappe/frappe/model/document.py", line 1322, in composer
    return composed(self, method, *args, **kwargs)
      self = <File: unsaved>
      args = ()
      kwargs = {}
      hooks = []
      method = 'before_insert'
      doc_events = {'*': {'on_update': ['frappe.desk.notifications.clear_doctype_notifications', 'frappe.workflow.doctype.workflow_action.workflow_action.process_workflow_actions', 'frappe.core.doctype.file.utils.attach_files_to_document', 'frappe.automation.doctype.assignment_rule.assignment_rule.apply', 'frappe.automation.doctype.assignment_rule.assignment_rule.update_due_date', 'frappe.core.doctype.user_type.user_type.apply_permissions_for_non_standard_user_type'], 'after_rename': ['frappe.desk.notifications.clear_doctype_notifications'], 'on_cancel': ['frappe.desk.notifications.clear_doctype_notifications', 'frappe.workflow.doctype.workflow_action.workflow_action.process_workflow_actions', 'frappe.automation.doctype.assignment_rule.assignment_rule.apply'], 'on_trash': ['frappe.desk.notifications.clear_doctype_notifications', 'frappe.workflow.doctype.workflow_action.workflow_action.process_workflow_actions'], 'on_update_after_submit': ['frappe.workflow.doctype.workflow_action.workflow_action.process_w...
      composed = <function Document.hook.<locals>.compose.<locals>.runner at 0x7f26f7a318a0>
      compose = <function Document.hook.<locals>.compose at 0x7f26f7a316c0>
      f = <function Document.run_method.<locals>.fn at 0x7f26f7a30ea0>
  File "apps/frappe/frappe/model/document.py", line 1304, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
      self = <File: unsaved>
      method = 'before_insert'
      args = ()
      kwargs = {}
      add_to_return_value = <function Document.hook.<locals>.add_to_return_value at 0x7f26f7a31760>
      fn = <function Document.run_method.<locals>.fn at 0x7f26f7a30ea0>
      hooks = ()
  File "apps/frappe/frappe/model/document.py", line 959, in fn
    return method_object(*args, **kwargs)
      self = <File: unsaved>
      args = ()
      kwargs = {}
      method_object = <bound method File.before_insert of <File: unsaved>>
      method = 'before_insert'
  File "apps/frappe/frappe/core/doctype/file/file.py", line 103, in before_insert
    self.save_file(content=self.get_content())
      self = <File: unsaved>
  File "apps/frappe/frappe/core/doctype/file/file.py", line 534, in get_content
    with open(file_path, mode="rb") as f:
      self = <File: unsaved>
      file_path = './<MYURL>/private/files/print_designer-ausgangsrechnung_v1-previewf5e512.jpg'
builtins.FileNotFoundError: [Errno 2] No such file or directory: './<MYURL>/private/files/print_designer-ausgangsrechnung_v1-previewf5e512.jpg'
samy4sam commented 1 month ago

After I returned to the previous image version, the PDF generation works again on the sites where it worked before. However, it still does not work on the broken website

samy4sam commented 1 month ago

@maharshivpatel I have the same error with my local dev installation. I tried it with the main and develop branch.

samy4sam commented 1 month ago

I have set up another new website, but with a different domain. I did everything the same and the PDF creation works. I checked the file systems of the working and the broken setup. There is no log file for the scheduler in the broken instance. Could the scheduler have something to do with the problem?

samy4sam commented 1 month ago

@maharshivpatel I have created another fresh site. The PDF generation worked perfectly. Then I imported the backup of the site with the generation problem onto this new page. After that, the PDF generation no longer worked. I therefore dropped the site and set it up again. But the PDF generation no longer works on this new page either. How can this be? I have deleted everything.