frappe / frappe

Low code web framework for real world applications, in Python and Javascript
https://frappeframework.com
MIT License
6.99k stars 3.33k forks source link

Error sending emails with 'Attach Document Print' #27562

Open SufyanSadiqOffice opened 2 weeks ago

SufyanSadiqOffice commented 2 weeks ago

New Print Format Builder : I created a print format using 'New Print Format Builder' on 'Job Offer' doctype. And while sending email with 'Attach Document Print' functionality in doctypes, I got error and email is not going.

The Error : Server Error AttributeError: 'str' object has no attribute 'get'

beingeek commented 2 weeks ago

Hi @SufyanSadiqOffice can you share error stack and all steps to reproduce (preferably with screenshots)?

SufyanSadiqOffice commented 1 week ago

1_ Format Builder Print Format 2_ Email Job Offer Doctype 3_ Attach Document Print 4_ Email Queue Records 5_ Open Email Queue 6_ Clicking On Send Now Button

SufyanSadiqOffice commented 1 week ago

Print Format code that is written on New Format Builder.

`

عرض وظيفي
Employment Offer
{{doc.offer_date}}




Job Details
Name {{doc.applicant_name}}
Job Title {{doc.designation}}
Job Grade {{doc.custom_grade}}
Department {{doc.custom_department}}
Monthly Salary & Allowances (SAR)
Basic Salary {% for row in doc.offer_terms %} {% if row.offer_term == 'Basic Salary' %} {{row.value}} {% endif %} {% endfor %}
Housing Allowance {% for row in doc.offer_terms %} {% if row.offer_term == 'Housing Allowance' %} {{row.value}} {% endif %} {% endfor %}
Transportation Allowance {% for row in doc.offer_terms %} {% if row.offer_term == 'Transportation Allowance' %} {{row.value}} {% endif %} {% endfor %}
Special Bonus {% for row in doc.offer_terms %} {% if row.offer_term == 'Special Bonus' %} {{row.value}} {% endif %} {% endfor %}
Gross Salary {% for row in doc.offer_terms %} {% if row.offer_term == 'Gross Salary' %} {{row.value}} {% endif %} {% endfor %}


{% if doc.terms and doc.custom_print_signature == 1 %} {{doc.terms}} {% endif %}


Signature & Date Tentative Joining Date


`

SufyanSadiqOffice commented 1 week ago

`### App Versions

{
    "erpnext": "15.15.0",
    "frappe": "15.18.2",
    "hrms": "15.14.2",
    "lending": "0.0.1",
    "lenel": "0.0.1",
    "sowaan_hr": "0.0.1",
    "zatca2024": "0.0.1"
}

Route

Form/Email Queue/6bde0da4cb

Traceback

Traceback (most recent call last):
  File "apps/frappe/frappe/app.py", line 110, in application
    response = frappe.api.handle(request)
  File "apps/frappe/frappe/api/__init__.py", line 49, in handle
    data = endpoint(**arguments)
  File "apps/frappe/frappe/api/v1.py", line 36, in handle_rpc_call
    return frappe.handler.handle()
  File "apps/frappe/frappe/handler.py", line 49, in handle
    data = execute_cmd(cmd)
  File "apps/frappe/frappe/handler.py", line 85, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "apps/frappe/frappe/__init__.py", line 1718, in call
    return fn(*args, **newargs)
  File "apps/frappe/frappe/utils/typing_validations.py", line 31, in wrapper
    return func(*args, **kwargs)
  File "apps/frappe/frappe/email/doctype/email_queue/email_queue.py", line 442, in send_now
    record.send()
  File "apps/frappe/frappe/email/doctype/email_queue/email_queue.py", line 167, in send
    message = ctx.build_message(recipient.recipient)
  File "apps/frappe/frappe/email/doctype/email_queue/email_queue.py", line 314, in build_message
    message = self.include_attachments(message)
  File "apps/frappe/frappe/email/doctype/email_queue/email_queue.py", line 387, in include_attachments
    print_format_file = frappe.attach_print(**attachment)
  File "apps/frappe/frappe/__init__.py", line 2175, in attach_print
    else get_print(doctype, name, **kwargs)
  File "apps/frappe/frappe/__init__.py", line 2129, in get_print
    response = get_response_without_exception_handling("printview", 200)
  File "apps/frappe/frappe/website/serve.py", line 47, in get_response_without_exception_handling
    return renderer_instance.render()
  File "apps/frappe/frappe/website/page_renderers/template_page.py", line 84, in render
    html = self.get_html()
  File "apps/frappe/frappe/website/utils.py", line 523, in cache_html_decorator
    html = func(*args, **kwargs)
  File "apps/frappe/frappe/website/page_renderers/template_page.py", line 95, in get_html
    self.update_context()
  File "apps/frappe/frappe/website/page_renderers/template_page.py", line 163, in update_context
    data = self.run_pymodule_method("get_context")
  File "apps/frappe/frappe/website/page_renderers/template_page.py", line 223, in run_pymodule_method
    return method(self.context)
  File "apps/frappe/frappe/www/printview.py", line 57, in get_context
    body = get_rendered_template(
  File "apps/frappe/frappe/www/printview.py", line 163, in get_rendered_template
    format_data_map[df.get("fieldname")] = df
AttributeError: 'str' object has no attribute 'get'

Request Data

{
    "type": "POST",
    "args": {
        "name": "6bde0da4cb"
    },
    "btn": {
        "0": {
            "jQuery370046732394056177821": {
                "events": {
                    "click": [
                        {
                            "type": "click",
                            "origType": "click",
                            "guid": 421,
                            "namespace": ""
                        }
                    ]
                }
            }
        },
        "length": 1
    },
    "headers": {},
    "error_handlers": {},
    "url": "/api/method/frappe.email.doctype.email_queue.email_queue.send_now",
    "request_id": null
}

Response Data

{
    "exception": "AttributeError: 'str' object has no attribute 'get'",
    "exc_type": "AttributeError"
}
SufyanSadiqOffice commented 1 week ago

Asalam Alikum @beingeek above are the screenshots of the process starting from creating print format to email it. Along with the screenshots i also provided the print format code and the error.

beingeek commented 1 week ago

W/salam, it seems like bug in print designer app Did you tried attaching attachment via some different print format (html or print format builder) ?

@SufyanSadiqOffice

SufyanSadiqOffice commented 1 week ago

@beingeek I created the formats through normal 'Print Format' and the emails are going but through 'Print Format Builder' (not the Print Designer) i am having error while sending email.

My desired print format is achieved through 'Print Format Builder' now the issue is that why it is giving error on sending email.

SufyanSadiqOffice commented 1 week ago

Salam, @beingeek any update ?

SufyanSadiqOffice commented 5 days ago

Salam, @beingeek any update ?