[FIXED] Generating PDF via Scheduled Task causes Internal server error

Has anyone been able to generate pdfs in a scheduled task?

I have a background task for generating and emailing PDFs. The method works fine when launched via a server method (called from a UI element) but fails every time it is called from a scheduled task.

Here is the error I get:

AnvilWrappedError: Internal server error: 48c84622de2b
at /downlink/anvil/pdf.py, line 17
called from /downlink/anvil/pdf.py, line 30
called from DailySummaryReport, line 37

Here is a simplified version of the code. I get the error whether or not I use PDFRenderer or call render_form() directly.

@anvil.server.background_task
def create_pdf_emails(target_dt=None, tz_str="US/Central"):
  
  if not target_dt:
    target_dt = datetime.now(pytz.timezone(tz_str)).date()
  
  # THIS NEXT LINE IS THE ONE THAT FAILS
  pdf1 = PDFRenderer(scale=0.6, filename="First.pdf").render_form('DailyPDFPlain', "obs", target_dt)
  pdf2 = PDFRenderer(scale=0.6, filename="Second.pdf").render_form('DailyPDFPlain', "checks", target_dt)
  
  anvil.email.send(...)

Could this be due to the fact that there is no UI instance when the method is called via a scheduled task?

Thank you for any advice.

Hi Matt,

Thanks for this - that definitely looks like an issue at our end. We’re looking into it now and will post here when we have an update for you.

[Moved to bug reports]

Thanks for the report - this should now be fixed! Can you check and see if it’s working now?

Looks like it is fixed now. Thank you!

1 Like