Cannot view private files after updating to version 13 from version 12 (frappe.exceptions.DuplicateEntryError)

I’m having trouble access trouble access private files after updating to erpnext. If I uncheck ‘is_private’ checkbox then the file shows up fine.

The traceback is as follow:

Traceback (most recent call last):
File “apps/frappe/frappe/model/base_document.py”, line 363, in db_insert
frappe.db.sql(“”"INSERT INTO tab{doctype} ({columns})
File “apps/frappe/frappe/database/database.py”, line 148, in sql
self._cursor.execute(query, values)
File “env/lib/python3.8/site-packages/pymysql/cursors.py”, line 148, in execute
result = self._query(query)
File “env/lib/python3.8/site-packages/pymysql/cursors.py”, line 310, in _query
conn.query(q)
File “env/lib/python3.8/site-packages/pymysql/connections.py”, line 548, in query
self._affected_rows = self._read_query_result(unbuffered=unbuffered)
File “env/lib/python3.8/site-packages/pymysql/connections.py”, line 775, in _read_query_result
result.read()
File “env/lib/python3.8/site-packages/pymysql/connections.py”, line 1156, in read
first_packet = self.connection._read_packet()
File “env/lib/python3.8/site-packages/pymysql/connections.py”, line 725, in _read_packet
packet.raise_for_error()
File “env/lib/python3.8/site-packages/pymysql/protocol.py”, line 221, in raise_for_error
err.raise_mysql_exception(self._data)
File “env/lib/python3.8/site-packages/pymysql/err.py”, line 143, in raise_mysql_exception
raise errorclass(errno, errval)
pymysql.err.IntegrityError: (1062, “Duplicate entry ‘AL-01229’ for key ‘PRIMARY’”)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “apps/frappe/frappe/app.py”, line 74, in application
response = frappe.utils.response.download_private_file(request.path)
File “apps/frappe/frappe/utils/response.py”, line 182, in download_private_file
make_access_log(doctype=‘File’, document=_file.name, file_type=os.path.splitext(path)[-1][1:])
File “apps/frappe/frappe/core/doctype/access_log/access_log.py”, line 28, in make_access_log
_make_access_log(
File “apps/frappe/frappe/init.py”, line 647, in wrapper_fn
retval = fn(*args, **get_newargs(fn, kwargs))
File “apps/frappe/frappe/core/doctype/access_log/access_log.py”, line 59, in _make_access_log
doc.insert(ignore_permissions=True)
File “apps/frappe/frappe/model/document.py”, line 253, in insert
raise e
File “apps/frappe/frappe/model/document.py”, line 250, in insert
self.db_insert()
File “apps/frappe/frappe/model/base_document.py”, line 381, in db_insert
raise frappe.DuplicateEntryError(self.doctype, self.name, e)
frappe.exceptions.DuplicateEntryError: (‘Access Log’, ‘AL-01229’, IntegrityError(1062, “Duplicate entry ‘AL-01229’ for key ‘PRIMARY’”))

I solve this problem this way for anyone who is having the same trouble.

The issue is similar laid out by this post: Print Preview Error {{body}} - #11 by brian_pond.

This involves the current value in tabSeries and the current value of the blank entry in the same table.

This is the code I used to solve my problem. I logged into my database as root and ran these command.

SELECT name, current FROM tabSeries WHERE name like ‘AL%’
±-----±--------+
| name | current |
±-----±--------+
| AL- | 2127 |
±-----±--------+

select name, current from tabSeries;

±---------------±--------+
| name | current |
±---------------±--------+
| | 1228 |
| ACC-ASS-2020- | 6 |

SELECT name, current FROM {erpnext_database_name}.tabSeries WHERE name= ’ ';

update {erpnext_database_name}.tabSeries set current = 2128 where name= ’ ';


After updating the blank field value to higher than that of the AL series, everything now works fine.