anvil.server.InternalError: Internal server error: b5e90f0b9b13
I’m still re-working my code related to this thread
Based on this thread
I’ve shifted to writing a Media Object (file) to Data Table, then I am passing that Data Table Row back to client code via Task State.
It has been working up until today, when I got the subject Internal Server Error.
The error has been intermittent, but it has happened 3 or 4 times today, so I thought I’d report it.
The Exception Message
anvil.server.InternalError: Internal server error: b5e90f0b9b13
at A_Main_Navigation, line 208
called from A_Main_Navigation, line 208
called from app/anvil_extras/utils/_timed.py:41
Related Code
The line (208) in question is the get_bytes().decode()
in the code block below
le_t_data = self.log_entry_task.get_state()
if 'log_entry_db_row' in le_t_data and not components[1].visible:
internal_file = le_t_data['log_entry_db_row']['alternate_file']
le_list = json.loads(internal_file.get_bytes().decode())
GlobalCache.global_dict['log_entries'] = le_list
GlobalCache.global_dict['log_entries_load_time'] = datetime.now(timezone.utc)
components[1].visible = True
Thoughts on Server Error???
I guess my primary question is the Internal Server Error
bad-luck?
In the Background task I am writing to Data Table as follows:
log_entries
is a list of dicts from a JSON data retrieved from an API call. About 4MB of data. ~15,000 records.
f_name = f'/tmp/{filename}.json'
with open(f_name, 'w', encoding="utf-8") as f:
json.dump(log_entries, f)
T.check("File write is done.")
new_row.update(alternate_file=anvil.media.from_file(f_name, mime_type='application/json'))
anvil.server.task_state['log_entry_status'] = 'file_written'
anvil.server.task_state['file_record_count'] = len(log_entries)
# try passing Data Table Row
anvil.server.task_state['log_entry_db_row'] = new_row
return
I found that dumping records to file system was faster than using BytesIO buffer, hence the file.
Is it possible that new_row.update
hasn’t actually completed it’s write before the function returns?
the log_entry_db_row
key is not added to the task state until the last line in the BG task. So the client code should not try to access that db row until its available.
Although this error does not happen on each run, it has occurred multiple times, any thought on how to avoid the exception?
Thanks.