Internal Anvil error?

I keep adding more print statements but it keeps happening in different places. The latest one (3d5dd71c8a) seems to have taken place during these lines:

now = sm.now()
proposal = proptime['proposal']
proptime['users_accepting'] = [user]
proptime['accept_date'] = now

proptime is a table row and sm.now() just calls:

def now():
  return datetime.datetime.utcnow().replace(tzinfo=anvil.tz.tzutc())

Again, these lines work as intended most of the time, but sometimes they don’t. I’m wondering whether it could have to do with timers calling server functions while another server function is running, but my understanding is that those are just queued.

Hi @hugetim,

An update - we’ve tracked this down to a bug in the underlying PyPy interpreter we use for sandboxing. As far as we can tell you’re the only person who can tickle this error, which is making for somewhat slow progress.

Would you be able to clone your app and produce a configuration that (at least intermittently) displays the fault on first load (ie without having to take too many repro steps)?

2 Likes

That’s very reassuring news! It will take me a few steps to adjust the user authorization (which currently depends on a Google sheet) and automate some things so that the clone will do what you need, but I should be able to do that this evening (Chicago time) and get it to you then.

[update: I sent you a message with a clone link and some brief instructions.]

If you’re not able to fix the underlying PyPy interpreter, any ideas on how I could change my code to avoid this issue as a workaround? Thanks!

(I briefly tried reverting Basic Python2 but having some trouble with circular import statements…)

A post was split to a new topic: Server code exited unexpectedly

I’m getting a similar issue. I can’t clone the app as there are some business sensitive parts to it. However I know it’s this function causing the issue every time. I used to get an out of memory issue but now it fails with the anvil error.

def xml_to_sql(root: ET.Element, model, element_name: str, data_elements: list, session: SqlAlchemySession):
    transaction = session.begin_nested()
    batch_size = 1000
    print("transactions started")
  
    try:
        session.query(model).delete()  # Clears out the table
        print("table cleared")
        column_types = {column.name: column.type for column in model.__table__.columns}
        probability_threshold = 0.001
        instances_added = 0
        element_count = 0
        for element in root.findall(f".//{element_name}"):
            data = {}

            element_count += 1
            if random.random() < probability_threshold:
                print(f"data element  {element_count} - {element_name}")
            for data_element in data_elements:
                text_value = element.findtext(data_element, default=None)  # Extract text value for the data element
                # Convert the string to the appropriate type based on the model's column
                if data_element in column_types:
                    column_type = column_types[data_element]
                    if isinstance(column_type, Integer) and text_value is not None and text_value.isdigit():
                        data[data_element] = int(text_value)
                    elif isinstance(column_type, String):
                        data[data_element] = text_value
                    elif isinstance(column_type, Date) and text_value is not None:
                        try:
                            # Assuming the date format in your XML is 'YYYY-MM-DD'
                            data[data_element] = datetime.strptime(text_value, '%Y-%m-%d').date()
                        except ValueError:
                            # In case the date format is incorrect or the field is empty
                            print(f"Date conversion error for value '{text_value}'")
                            data[data_element] = None
                    else:
                        # For any other type that doesn't require special handling
                        data[data_element] = text_value
                else:
                    # If the element is not found in column types, use the default value
                    data[data_element] = text_value

                instance = model(**data)
                session.add(instance)
                
                instances_added += 1
                batch_size += 1
                
                if instances_added % batch_size == 0:
                    session.flush()  # Flush the batch to the database but do not commit yet
                    print(f"Flushed a batch of {batch_size} records.")

        # Commit the transaction only if all batches are processed successfully
        transaction.commit()
        print("All batches committed successfully.")

'''

The output was this:

trying xml_to_sql

transactions started

table cleared

data element 365 - AMP

data element 1018 - AMP

data element 2869 - AMP

data element 3375 - AMP

data element 3998 - AMP

data element 6758 - AMP

data element 7195 - AMP

data element 7447 - AMP

data element 8814 - AMP

data element 9447 - AMP

data element 10511 - AMP

data element 11408 - AMP

data element 14226 - AMP

data element 14367 - AMP

data element 14900 - AMP

data element 15357 - AMP

data element 16497 - AMP

data element 16995 - AMP

data element 17371 - AMP

data element 17735 - AMP

data element 18066 - AMP

anvil.server.ExecutionTerminatedError: Server code exited unexpectedly: 652e9c8fbf

It fails somewhere randomly during the data element count.

Please create a new post.

No one is going to respond to something 3 year old.

2 Likes