Changes in how media objects are loaded/rendered?

I have longstanding code that creates .pdfs. A lot of my images, logos, etc., load by including a Image object and I dynamically set the source attribute to a lazy media object. It has worked… for months.

Now… it’s not.

Any changes, intended or otherwise?

Not that I’m aware of. Can you share a clone?

I can’t … the code is so huge and dependent on sensitive data. I’m looking at how I’ve used z-index to fix a different problem, that is the only change I can think of that I believe occurred around the time I recall everything working just fine

OK, let’s try some simple stuff. In a dev version of your app, make a new form, load a Media object from the database (make a special server function for testing, just return something), then set the source of an Image component to that. If that’s not working, we know it’s something global to your app; if it is working then we can gradually work our way from there to something that’s not working.

Tested this and it’s working fine…

https://anvil.works/build#clone:VGK5S55HAMOIAHX2=ZKCRQBVVBMY5DH5D3WIWB5Q2

That app prints a PDF from a form that has an Image component on it.

So, from that app, can I infer a bit more detail about your problem? You’re creating a PDF from a form with an Image component on it, and the Image component isn’t loading for you?

When do you dynamically set this image source? Is it during __init__ of the toplevel form, or the show event, or somewhere else?

All correct. The actual Image file is pulled from an Anvil table in a server background task, it is bundled up with other data into a dictionary. That dictionary is sent via the PDF_Renderer to a ‘base’ form as a parameter. Logic in this ‘base’ form determines which other, imported forms are included in the final report. The dictionary is passed to these forms, and one key/element is ‘logo.’

I’ve debug printed and verified that the logo file is arriving.

The Image component source is set in the form’s init as follows:

class aa_cover(aa_coverTemplate):
  def __init__(self, date, logo, mswcacs, **properties):
    self.init_components(**properties)

    self.date.text = date

    if mswcacs == 'msw':
      self.cover_title.text = 'Financial Impact of Threats\nA Statistical Analysis'
      self.cover_title.font_size = 28
      self.cover_title.y = 748.703125
      self.image_1.source = '_/theme/ar_blank_msw.jpg'
      self.lfooter.text = "contact@g2sglobal.com"
      self.rfooter.text = "2022 G2S Global, LLC   All Rights Reserved"
    else:
      self.cover_title.text = "Cyber Threat Analysis"
      self.cover_title.fontsize = 42

    print(logo)
    self.logo.source = logo   

What happens if you roll back your current development (not published) branch to before you made any of these changes?
If it’s still broken then, at least you ruled that part out and then you can restore back up to the version you are working on right now and can move on to knowing for sure that its something else.

Good thought… and honestly this is what is most disconcerting. I rolled back to several versions, all the way back to early April, and the logo is still not rendering when I KNOW 100% it was, reliably

Ok, so the only last thing I can think of that could be checked is that something is not blocking the process to wait for the results of your background task (before its added to the dictionary), and something about anvil changed that either sped up or delayed something that wasn’t causing a race condition in the past, but now is?

I’m trying to think backwards from what could have changed in anvil from before to now that could also affect anything in the chain that goes from the data table to the render.

When this happens to me it is usually because I wrote something that was broken but still worked anyways, and then anvil updated and the broken code that shouldn’t have worked finally stopped working.

Also, I loaded your clone, you might also benefit from moving imports into your server module functions, or using the decorator code I wrote for lazy loading, I tested a few times a function that does nothing but print(1) and every time you call the server module it takes 3.5-5.5 seconds to load all of the imports:
image

I’ll look at things from the perspective of this line of thinking, thanks