Duplicate entry when creating new doc

Hi

I have created a server script ( client side ) of type scheduler.

Thsi script fetches data and processes it ( I suspect all that detail
is not necesary at this stage )
I then create a new doc


    weather_doc = frappe.get_doc({
        'doctype': 'Weather',
        'date': frappe.utils.nowdate()
    })
    weather_doc.insert()

but eerytime the script runs, I get the following error

frappe.exceptions.DuplicateEntryError: ('Weather', 'WEA-2024-08-13-location', IntegrityError(1062, "Duplicate entry 'WEA-2024-08-13-location' for key 'PRIMARY'"))

And I checked. There are no existing docs currently on the system ?

Then the record still exists in the database but is not showing (check if you have any filters on).

You can keep it safe and append a number to the document name if a duplicate entry exists.

@trainingacademy try this

If not frappe.db.exists(‘Weather’,{date’: frappe.utils.nowdate()}):
weather_doc = frappe.get_doc({
‘doctype’: ‘Weather’,
‘date’: frappe.utils.nowdate()
})
weather_doc.insert()

Thank you @Yamen_Zakhour for the message
I confirm that there are no docs that I can see on the Desk and I have
checked the filters : no filters set
I also have logged onto the backend and checked the actual database table. a SELECT * yields an “Empty Set” response.

The naming is defined as follows…
format:WEA-{date}-{location}-{###}

I have also added the {###} so that the auto-naming can add its own
sequence number. So the number it adds is “001” which implies that “001”
is the next sequence. Then the error is:

frappe.exceptions.DuplicateEntryError: ('Weather', 'WEA-2024-08-13-location-001', IntegrityError(1062, "Duplicate entry 'WEA-2024-08-13-location-001' for key 'PRIMARY'"))

Thank you @Jeel for the message

I inserted the code suggestion but it still attempts to create the doc and also raise
the same error.

This implies that the frappe.db.exist - check finds no doc and therefor proceeds
to create one. And yet the same error is occuring.

I think what I must try…
I actually created a V13 server just to install the Agriculture module. But while writing
this server-script code, I noticed that “frappe.new_doc” is not available in "server-script| ( client side). That is why I opted for frappe.get_doc. Let me see if Agricuture
will install on V14. I did pick up some problems in thsi regard in the dicussion forum
before I installed V13, but let me see if it will install on V14. V14 has
“frappe.new_doc” available in “server_script”