Repeating Panel Not Updating as Expected

I’m trying to update a repeating panel grid once the user edits the information in a row. It gives an alert form, and when the user saves, it sends an event value back to the form that triggers a function to update the repeating panel items. But it’s not working. Here is a GIF that shows the issue.

When the user clicks the edit button inside the repeating panel:

from ...EditCoupon import EditCoupon
from .. import AllCoupons
...
  def edit_click(self, **event_args):
    """This method is called when the button is clicked"""
    response = anvil.alert(EditCoupon(coupon_id=self.item['id']), buttons=[],large=True)
    if response == 'updated':
      AllCoupons().populate_coupons()

The relevant form code that is being pop-ed up as an alert:

  def save_button_click(self, **event_args):
    """This method is called when the button is clicked"""
    response = anvil.server.call('update_coupon', 
                                self.coupon_id_label.text, 
                                self.title.text,
                                self.status_dropdown.selected_value,
                                self.short_description.text,
                                self.long_description.text,
                                self.category.selected_value,
                                self.location.text,
                                self.original_price.text,
                                self.price.text,
                                self.restriction.text,
                                self.image.source,
                                self.start_date.date,
                                self.end_date.date,
                                self.phone.text,
                                self.address.text,
                                self.special_instructions.text,
                                self.coordinates.text
                              )
    if response == 'success':
      self.raise_event("x-close-alert", value='updated')
      n = Notification('Coupon has been updated succesfully.')
      n.show()
    else:
      n = Notification('Error, please try again later.')
      n.show()

The event value is being passed back to the repeating panel template form and the function on AllCoupons is called:

  def populate_coupons(self, **event_args):
    self.repeating_panel_1.items = anvil.server.call('populate_coupons')

But as you can see from the GIF, the data on the repeating panel is not being updated. What’s going on?

Are you sur the populate_coupons is executed?

Have you tried adding a few prints and checking the log to see what’s executed?

When adding a print statement it seems to be firing twice.

  def populate_coupons(self, **event_args):
    self.repeating_panel_1.items = anvil.server.call('populate_coupons')
    print('items populated')

And just to be sure it’s not being called from somewhere else, here is where that function is called from.

The way you’re calling AllCoupons().populate_coupons(), is AllCoupons() the actual instance of the AllCoupons form displayed? Maybe try replacing the print statement with something that writes to a label on that form and see if that works.

First of all I have no clue what’s happening in your case.
… but when items is updated twice in a row with a server call, you could have the second call responding before the first one and the form could be rendering the updated data correctly and then could be rendering the old data back so quickly that you don’t even see it.

Try to put more prints, before and after the call, with some sort of id like a timestamp or a global counter set when you enter the function.

Perhaps when you figure out why you have 2 calls you also understand what’s wrong.

I separated the populate and update functions to help isolate things. The update function is now:

  def update_coupons(self, **event_args):
    print('pre-update ', datetime.datetime.now())
    self.repeating_panel_1.items = anvil.server.call('populate_coupons')
    print(self.repeating_panel_1.items[0]['start'])
    print('post-update ', datetime.datetime.now())
    self.add_component(Label(text='it worked!'))

It is being called from the repeating panel template form:

  def edit_click(self, **event_args):
    """This method is called when the button is clicked"""
    response = anvil.alert(EditCoupon(coupon_id=self.item['id']), buttons=[],large=True)
    if response == 'updated':
      AllCoupons().update_coupons()

The data is clearly updated, but it is not showing in the form.

Well I don’t know what is happening, but it can be easily fixed by simply refreshing the page a la:

  def update_coupons(self, **event_args):
    get_open_form().content_panel.clear()
    get_open_form().content_panel.add_component(AllCoupons())

That seems consistent with my theory of the case.