Autoname in Scripts not working

I was trying to make a new entry on Doctype name Club using the server side script.
So i currently have a Doctype name Donation Subscription
which has a field called club which i want to be autofetched based in the amount
So the club list works like this:
When we want to make a new club we just give input as Amount:
These are the fields in the club:

1
Club Details - Section Break - club_details_section

2
Education - Section Break - education_section

3
Amount - Currency - amount

And the naming format for it is:
Naming Rule:
Expression
Autoname:
format: Education-{amount}

And the script has this init:

Check if a club with the given amount exists

existing_club = frappe.db.get_value(“Club”, {“amount”: doc.cost}, “name”)

if existing_club:
doc.club = existing_club # Assign existing club
else:
# Create new club if it does not exist
new_club = frappe.get_doc({
“doctype”: “Club”,
“amount”: doc.cost # Only set the amount, Frappe will generate the name
})
new_club.name = f"Education-{doc.cost}"

new_club.insert(ignore_permissions=True)


# Fetch the actual name generated by the system
doc.club = new_club.name

But the name for new clubs always comes out to be “Education-”

Can someone help me out with this?

In what event does this script execute?
Are you sure the “doc.cost” returns a value?
What is the value of “new_club.name” before and after the insert ()?
A lot of ways to debug this.

So i am not using bench.
I am directly executing it in Frappe site on server scripts
Yes doc.cost gives a value but
i dont know how can can i debug it with the help of frappe