Problem with appending and deleting linked images - clone supplied

Hi, I have 2 issues I would appreciate help with:-

  1. When I upload, I am trying to add(append to dict) different images, my code appends 4 images, but they are all the same? Only image 1 gets added 4 times.

  2. When I try and delete one, using the unique id(uid), I get this error
    anvil.tables.TableError: Column 'UniqueID' can only be searched with a number (not a media) in table 'mystuff'
    But I did a print statement on uid and it is a number???

Here is a clone of what I have.
https://anvil.works/build#clone:OVKKWUX4JYIIKTJ5=2C5RJ447TYROZLKNK5MO7Q6M

Look at the code you’re using to build the dict with the images:

    for x in self.file_loader_images1.files: 
        dict_images.append({
           "MyStuffImage":  self.file_loader_images1.file,
           })

In this, what does the variable x represent? What does self.file_loader_images1.file represent? Which one is going into your dict_images?

Look at the code that calls that server function:

anvil.server.call('delete_image', uid, self.item['MyStuffImage'])

And the server function itself:

def delete_image(MyStuffImage, uid):

Notice anything different between them? I guarantee you didn’t do print(uid) on the server, which is where the error was happening. Always do your diagnostic print statements as close to the line with the error as possible.

1 Like

Thanks for the reply, its much appreciated. I’ve now solved the first error, I created two variables and then used those in the loop instead of the direct field reference.

But the second one I’m still stumped on. You are right I didnt do the print on the server. I tried creating a variable of sel.item[‘MyStuffImage’] and passing that to the server, I tried switching the order of the variables, which has stopped the number error.

Now I’m getting another error:
anvil.tables.TableError: Cannot use a Media object as a search query

Will I need to add another column in mystuffimage in order to search on that table, the uid is from the mystuff table so I can access the correct row there?

Yes, you’ll need some way of uniquely identifying a row in that table. Your current two columns combined do uniquely identify a row, but you can’t use one of them in a search, so you’ll need another column that you can use in a search. A unique integer would work fine.

1 Like

EDIT: The data binding issue wasnt what I thought. Its caused a dangling reference. How to handle dangling references to deleted records

Seems you cant do much about it, so I’m thinking I will have to add another column on my images, and instead of deleting, it will change the status of the image to archived, then when I do my server query to get the images, I’ll have to add that extra line in. It seems a long way to go around the problem???

Showing more of that example from the docs:

zaphod = app_tables.people.get(Name="Zaphod Beeblebrox")
ford_prefect = app_tables.people.get(Name="Ford Prefect")

zaphod["Friends"] = [r for r in zaphod['Friends'] if r != ford_prefect]

Look at what the ford_prefect variable contains. Not a single column value, but the entire row whose link should be removed.

1 Like

I see, I’ve just changed it now, and it did delete the link… … and some more from records below it. :weary: :weary: :weary: well its 00:30 here now and I am very tired, so hopefully I can look at it with fresher eyes in the morning.
Have a great evening… and thanks again.
EDIT. Its working, dont know what happened last night, but I’ve done a few this morning and that hasn’t happened again. :tada: :confetti_ball: :trophy: :trophy: