[FIXED] PDF generation fails when used in a scheduled task

Hi all, I’d like to list a possible bug here.

What I’m trying to do:

  • generate PDF attachments and send an email by a scheduled task

What I’ve tried and what’s not working:
The PDF generation code that I am using functions properly if it is invoked by an @anvil.server.callable that uses anvil.server.launch_background_task(). However, if I attempt to use the same @anvil.server.background_task directly in the task scheduling service, the task is invoked but the below error is returned. Again, the same code works fine when called without the scheduling service and breaks when used with the scheduling service.

Code Sample:
This is simplified and it works:

@anvil.server.callable
def send_pdf_email():
  task = anvil.server.launch_background_task('send_pdf_email_task')
  return task

  
@anvil.server.background_task
def send_pdf_email_task():
    pdf1 = anvil.pdf.PDFRenderer( .... )

The same send_pdf_email_task() breaks with the following error when scheduled with the task scheduling service. No changes in the above code that otherwise functions as expected.

Error:
AnvilWrappedError: Internal server error: 56cba5505755at
/downlink/anvil/pdf.py, line 17
called from /downlink/anvil/pdf.py, line 43

Thank you.

Hi @krasen,

Thanks for reporting this, it does sound like a bug. We will investigate and get back to you!

[Moved to Bug Reports]

1 Like

A follow-up … now no scheduled task executes at all for me. Once the task is scheduled, the service never shows the next execution time/date in the gray field.

Something like this expected (taken from the docs):

Hi @krasen,

Do you have a published version of your app? Only tasks scheduled in the published version will run.

2 Likes

Hi. Thank you for clarifying this. The tasks do show up there when the app is published.

Also, I’d like to point out that the issue with the pdf generation in a scheduled task seems to be fixed. I am running code structured as in the description above and it is working correctly.

1 Like