psycopg2.errors.SerializationFailure when creating multiple documents concurrently in Frappe v15 wit

We are running Frappe v15 with PostgreSQL and experiencing the following error when creating documents:

psycopg2.errors.SerializationFailure: could not serialize access due to concurrent update

Stack trace highlights:

File "apps/frappe/frappe/model/document.py", line 304, in insert
  self.set_new_name(...)
File "apps/frappe/frappe/model/naming.py", line 246, in set_name_by_naming_series
  doc.name = make_autoname(doc.naming_series + ".#####", "", doc)
File "apps/frappe/frappe/model/naming.py", line 390, in getseries
  current = (frappe.qb.from_(series).where(series.name == key)
             .for_update(nowait=False).select("current")).run()

  • This happens when the same function to create a document is called multiple times concurrently, for example in loops, scheduled jobs, or API calls.
  • The error occurs because PostgreSQL cannot serialize concurrent updates to the same tabSeries row used for naming series.

Current setup:

  • Frappe v15
  • PostgreSQL database
  • Using autoname with naming series like DOC-.#####

Has anyone experienced this in Frappe v15 with PostgreSQL and found a clean solution for high-concurrency situations?

Thanks in advance!