pymysql.err.IntegrityError and DuplicateEntryError errors when open private files

I get this error when I open private files in the system
Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py”, line 324, in db_insert
), list(d.values()))
File “/home/frappe/frappe-bench/apps/frappe/frappe/database/database.py”, line 156, in sql
self._cursor.execute(query, values)
File “/home/frappe/frappe-bench/env/lib/python3.5/site-packages/pymysql/cursors.py”, line 170, in execute
result = self._query(query)
File “/home/frappe/frappe-bench/env/lib/python3.5/site-packages/pymysql/cursors.py”, line 328, in _query
conn.query(q)
File “/home/frappe/frappe-bench/env/lib/python3.5/site-packages/pymysql/connections.py”, line 517, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File “/home/frappe/frappe-bench/env/lib/python3.5/site-packages/pymysql/connections.py”, line 732, in _read_query_result
result.read()
File “/home/frappe/frappe-bench/env/lib/python3.5/site-packages/pymysql/connections.py”, line 1075, in read
first_packet = self.connection._read_packet()
File “/home/frappe/frappe-bench/env/lib/python3.5/site-packages/pymysql/connections.py”, line 684, in _read_packet
packet.check_error()
File “/home/frappe/frappe-bench/env/lib/python3.5/site-packages/pymysql/protocol.py”, line 220, in check_error
err.raise_mysql_exception(self._data)
File “/home/frappe/frappe-bench/env/lib/python3.5/site-packages/pymysql/err.py”, line 109, in raise_mysql_exception
raise errorclass(errno, errval)
pymysql.err.IntegrityError: (1062, “Duplicate entry ‘AL-01348’ for key ‘PRIMARY’”)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/app.py”, line 66, in application
response = frappe.utils.response.download_private_file(request.path)
File “/home/frappe/frappe-bench/apps/frappe/frappe/utils/response.py”, line 179, in download_private_file
make_access_log(doctype=‘File’, document=_file.name, file_type=os.path.splitext(path)[-1][1:])
File “/home/frappe/frappe-bench/apps/frappe/frappe/core/doctype/access_log/access_log.py”, line 35, in make_access_log
doc.insert(ignore_permissions=True)
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 247, in insert
raise e
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 244, in insert
self.db_insert()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/base_document.py”, line 334, in db_insert
raise frappe.DuplicateEntryError(self.doctype, self.name, e)
frappe.exceptions.DuplicateEntryError: (‘Access Log’, ‘AL-01348’, IntegrityError(1062, “Duplicate entry ‘AL-01348’ for key ‘PRIMARY’”))

Status: 409

I try to chmod 777 for (private and files) directories, but also does not work.

I reset the recorde which has empty name in tabSeries table with the last Access Log DocType name and it works correctly.

Plugging my post here since my error is very similar to yours. Maybe you can help me figure out a fix.