TypeError: argument of type 'datetime.date' is not iterable when trying to print a document

Expected Behaviour
Print a document according to a custom or standard print format.

Actual Behaviour
Displays the following error when trying to print a document(for both standard and custom print formats):

Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/website/render.py”, line 39, in render
data = render_page_by_language(path)
File “/home/frappe/frappe-bench/apps/frappe/frappe/website/render.py”, line 134, in render_page_by_language
return render_page(path)
File “/home/frappe/frappe-bench/apps/frappe/frappe/website/render.py”, line 150, in render_page
return build(path)
File “/home/frappe/frappe-bench/apps/frappe/frappe/website/render.py”, line 157, in build
return build_page(path)
File “/home/frappe/frappe-bench/apps/frappe/frappe/website/render.py”, line 171, in build_page
if context.title and “{{” in context.title:
TypeError: argument of type ‘datetime.date’ is not iterable

Steps to reproduce:
I am working on a custom docType called ‘Employment Tax’ that calculates tax and related information. I have completed my work on the docType as it produced the intended result. But I keep getting the error message that I showed above when I try to prepare a custom print format that fetches some calculated values and parameters like date_of_joining and work_tax from the docType and populates fields and tables that I’ve prepared in the print format.

So, the steps to reproduce the issue are:

  1. Create a new Employment Tax document
  2. Fill out the necessary fields including child tables
  3. Save and print the document
    Frappé version: v9.1.5
    ERPNext version: v9.1.3

Can you post your Custom Print format. Looks like it is expecting a string where you are passing a datetime object.
You could try converting your datetime fields to string in the custom print format e.g.


Coincidentally same general problem here!? Event Data Import argument of type ‘datetime.datetime’ is not iterable - #4 by clarkej

@vijaywm Thank you for your reply.

I think I found the problem. While making the doctype, I had the ‘Title Field’ of the doctype set to ‘end_date’ because I wanted the documents to be listed by their end dates. When I change this to the ‘company’ field name, it works(i.e. the printing works). But I don’t know what this has to do with the custom print format because I haven’t even used the ‘end_date’ field name in the custom print format. Besides, I have no fields of type datetime. It would be great if someone can explain this.

if context.title and “{{” in context.title:

this is looking for a string value in context.title, where you have a datetime. I guess it means only strings are allowed in Title.

Thanks, @vijaywm.
Now it makes sense.