Doctype title_field not working properly with virtual fields - error on creating document

I am trying to set the field full_name as title field using GUI of frappe

Fields:
first_name: data
last_name: data
full_name: virtual field, data, options: f"{first_name} {last_name}"

then set Title Field as full_name

Now try to create a item using GUI, it gives “first_name not defined error”
It does work when you specifically define full_name as property in the test.py file - a friend of mine suggested, but i don’t exactly understand why?

p.s. I tried using options:f"{doc.first_name} {doc.last_name}" ended with error “pattern not found”

Simple answer: Title Field need real field instead of Virtual Field.

Virtual Doctype is a logic data, so it needs to be “calculated” first.
When inserting, Title Field try to find the first_name but it is still not available (not inserted). So it throws an error.

1 Like

Yes that makes sense. A better way can be to not use virtual field and set the value using before_insert hook

def before_insert(doc):
		doc.full_name = doc.first_name + doc.last_name # when full_name is not virutal
		return

Few things I found, not sure if they work on other releases too ( I am using Dev Branch. )
with using ‘doc’

full name: virtual field, options= doc.first_name + doc.last_name works


know that f string syntax is not working for me: options = f"{doc.first_name} {doc.last_name}" gives error when we create a document.