Exception on pdf rendering

What I’m trying to do:
I am rendering a form and it randomly gives me an exception that doesn’t provide much insight.

I am trying to understand the exception.

What I’ve tried and what’s not working:

The sample code below works 90% of the time, but randomly raises the following exception. The way I have circumvented the issue is to attempt until success. I have put in a loop to try 3 times, which has increased my success rate. However, I would much rather understand and resolve the underlying issue.

Code Sample:

@authenticated_callable
def generate_sales_order(data,name=None):
    order = data['order']
    pdf = create_pdf(data,name)
  except Exception as e:
    server_logger.error(f"Exception message: {e} for {order['order_number']} when trying to complete")
    return

  return pdf


@authenticated_callable
def create_pdf(data,name=None):
    notes = get_note_by_order(data['order'],private=True)
    if name:
      server_logger.debug(f"BEFORE RENDER STARTS")
      pdf = PDFRenderer(filename=name,quality="printer").render_form('app.utils.forms.PDFs.FORM',data=data,pdf=True,notes=notes)
    else:
      pdf = PDFRenderer(quality="printer").render_form('app.utils.forms.PDFs.FORM',data=data,pdf=True,notes=notes)
    return pdf

Error:

server_log-DEBUG 2022-09-26 13:28:04: BEFORE RENDER STARTS ***********

server_log-ERROR 2022-09-26 13:28:08: Exception message: "'0'" for 5001 when trying to complete

Clone link:
I am not allowed to release company code and the simple example does not yield this error.

Any direction would be much appreciated. The pdf does not make any server calls beyond the data I pass into it. I also have multiple log statements in the Form being rendered that are not logged.

EDIT

When running the same code in the IDE, it does not raise the exception.

EDIT 2
Here is the traceback. I raised the error after the server-log ERROR in the try/except clause:

KeyError: '0'
at /downlink/anvil/tables/v2/_utils.py, line 129
called from /downlink/anvil/tables/v2/_utils.py, line 89
called from /downlink/anvil/tables/v2/_search.py, line 157
called from /downlink/anvil/tables/v2/_search.py, line 165
called from /downlink/anvil/_server.py, line 917
called from /downlink/anvil/_server.py, line 934
called from /downlink/anvil/_server.py, line 940
called from /downlink/anvil/_server.py, line 934
called from /downlink/anvil/_server.py, line 998
called from /downlink/anvil/_serialise.py, line 134
called from /downlink/anvil_downlink_worker/full_python_worker.py, line 49
called from /downlink/anvil/server.py, line 54
called from /downlink/anvil/pdf.py, line 17
called from /downlink/anvil/pdf.py, line 4
1 Like

@anthonys Thanks for reporting, moved to bug reports.

Do you have a clone link you can share?
Feel free to send this via private message

1 Like