New issue with writing list of rows to a multiple row column

The following code has been working for months:

    e_and_o_policy = app_tables.agents_e_and_o_policies.add_row(agent=user,
                                                                    policy_upload=policy_upload,
                                                                    policy_number=policy_number,
                                                                    carrier=carrier,
                                                                    coverage_amount=float(coverage_amount),
                                                                    aggregate_amount=float(aggregate_amount),
                                                                    coverage_start_date=coverage_start_date,
                                                                    coverage_end_date=coverage_end_date,
                                                                    coverages=coverages,
                                                                    active=True,
                                                                    uuid=str(uuid.uuid4()),
                                                                    created_by=me,
                                                                    created_at=datetime.datetime.now(anvil.tz.tzutc())
                                                                   )

is now returning the following error:

anvil.tables.TableError: Column 'coverages' is a liveObjectArray - cannot set it to a liveObjectArray

First attempt to adjust code to see what might be going on:

    e_and_o_policy = app_tables.agents_e_and_o_policies.add_row(agent=user,
                                                                    policy_upload=policy_upload,
                                                                    policy_number=policy_number,
                                                                    carrier=carrier,
                                                                    coverage_amount=float(coverage_amount),
                                                                    aggregate_amount=float(aggregate_amount),
                                                                    coverage_start_date=coverage_start_date,
                                                                    coverage_end_date=coverage_end_date,
                                                                    active=True,
                                                                    uuid=str(uuid.uuid4()),
                                                                    created_by=me,
                                                                    created_at=datetime.datetime.now(anvil.tz.tzutc())
                                                                   )
        print('coverages: {}'.format(repr(coverages)))
        new_coverages = []
        for coverage in coverages:
          print('coverage: {}'.format(coverage['name']))
          new_coverages += app_tables.ins_coverages.get(name=coverage['name'])
        e_and_o_policy['coverages'] = new_coverages

yields this output and error:

coverages: [<LiveObject: anvil.tables.Row>, <LiveObject: anvil.tables.Row>, <LiveObject: anvil.tables.Row>, <LiveObject: anvil.tables.Row>] 
coverage: Health 
coverage: Indexed/Fixed Annuity 
coverage: Life 
coverage: Medicare

anvil.tables.TableError: Column 'coverages' is a liveObjectArray - cannot set it to a simpleObject

second edit to try to determine the issue:

    e_and_o_policy = app_tables.agents_e_and_o_policies.add_row(agent=user,
                                                                    policy_upload=policy_upload,
                                                                    policy_number=policy_number,
                                                                    carrier=carrier,
                                                                    coverage_amount=float(coverage_amount),
                                                                    aggregate_amount=float(aggregate_amount),
                                                                    coverage_start_date=coverage_start_date,
                                                                    coverage_end_date=coverage_end_date,
                                                                    active=True,
                                                                    uuid=str(uuid.uuid4()),
                                                                    created_by=me,
                                                                    created_at=datetime.datetime.now(anvil.tz.tzutc())
                                                                   )
        print('coverages: {}'.format(repr(coverages)))
        for coverage in coverages:
          print('coverage: {}'.format(coverage['name']))
          if e_and_o_policy['coverages'] is None:
            e_and_o_policy['coverages'] = [app_tables.ins_coverages.get(name=coverage['name'])]
          else:
            e_and_o_policy['coverages'] += app_tables.ins_coverages.get(name=coverage['name'])

yields the following output and error:

coverages: [<LiveObject: anvil.tables.Row>, <LiveObject: anvil.tables.Row>, <LiveObject: anvil.tables.Row>, <LiveObject: anvil.tables.Row>] 
coverage: Health 
coverage: Indexed/Fixed Annuity

anvil.tables.TableError: All elements of a table-row list must be rows from the same table

This seems to be something wrong with Anvil itself. The code has been working, nothing has changed, I can edit the row in the dev environment and link to the desired rows without any errors. Am I missing something?

Got it working with the following edit:

e_and_o_policy = app_tables.agents_e_and_o_policies.add_row(agent=user,
                                                                policy_upload=policy_upload,
                                                                policy_number=policy_number,
                                                                carrier=carrier,
                                                                coverage_amount=float(coverage_amount),
                                                                aggregate_amount=float(aggregate_amount),
                                                                coverage_start_date=coverage_start_date,
                                                                coverage_end_date=coverage_end_date,
                                                                active=True,
                                                                uuid=str(uuid.uuid4()),
                                                                created_by=me,
                                                                created_at=datetime.datetime.now(anvil.tz.tzutc())
                                                               )
    print('coverages: {}'.format(repr(coverages)))
    for coverage in coverages:
      print('coverage: {}'.format(coverage['name']))
      if e_and_o_policy['coverages'] is None:
        e_and_o_policy['coverages'] = [app_tables.ins_coverages.get(name=coverage['name'])]
      else:
        e_and_o_policy['coverages'] += [app_tables.ins_coverages.get(name=coverage['name'])]

Still don’t understand why this just stopped working.

1 Like

A plea to the Anvil gods here:

The original code was passing a list of data table rows and has been reliably saving for some time. This kind of random breakage is disconcerting and we frequently use this pattern to set the value of a multiple row reference column, and this one specific instance just randomly breaking raises the question of whether or not a full code-base review is called for, and every instance of code similar to

coverages=coverages

where the left-hand side is a multiple row reference column and the right-hand side is a pre-composed list of data tables rows, needs to be refactored to match the code that we got working (which is much less terse) before it also randomly fails.

1 Like

I think I’m running into this same issue–it’s very disconcerting and causing me major grief as I’m trying to do something that’s time sensitive. I have not been able to come up with a work around as I’m trying to retrieve the linked rows by their row IDs.

I was able to resolve my issue.

I now have this problem.

Hi folks,

We’re aware of this bug and are investigating. If anyone can share a reliable reproduction case, that would really help us narrow down the problem.

[Moved to bug reports]

2 Likes