AnvilWrappedError: 'NoneType' object does not support item assignment

Hi all - can anyone help me troubleshoot (or understand) this error message that a Tester using her iPad is getting please?

I’ve been unable to reproduce the error on Windows or Android. It comes up after entering Display Name = “JJF”, County = “Exeter, Devon”, Street = “River Plate Road”, House Number = (whatever).

https://anvil.works/build#clone:P33PVE5OAIUCIJY3=TH42XLEGYI2TOLUOUTEK7QAO

Here’s the App Log entry:

Relevant Server code:

@anvil.server.callable
def save_user_setup(field, value):
    """ General purpose save to the User database """
    user = anvil.users.get_user()
    user[field] = value

And Client code:

def get_input_fields(self):
    """ Returns a dictionary of database column headings and corresponding components/attributes """
    return {'display_name' : (self.display_name, 'text'),
           'house_number' : (self.house_number, 'text'),
           'street' : (self.street, 'selected_value'),
           'town' : (self.town, 'selected_value'),
           'county' : (self.county, 'selected_value'),
           'country' : (self.country, 'text'),
           'postcode' : (self.postcode, 'text'),
           'telephone' : (self.telephone, 'text'),}
  
def save_input(self, **event_args):
    """This method is called when the .my_details container is finally closed (after clicking OK) """
    input_fields = self.get_input_fields()
    for field, _values in input_fields.items():
        component, attribute = _values
        anvil.server.call("save_user_setup", field, getattr(component, attribute))

My guess is that your final server line (user[field] = value) is where the problem lies. Are you certain you have a logged in user at that point?

3 Likes

That syntax where you set the value of a dict is called assignment, so this error means you’ve tried to use it somewhere where you expected to have a dict but you’ve actually got None instead.

1 Like

Wow @owen.campbell thanks so much for the speedy reply and you were absolutely right!

Because we all had “remembered” users from previous sessions, the developers here were creating new users with user = <previously logged in user>.

The completely new Tester was starting with user = None and although I’d included self.force_user_setup() in each of the menu objects, I’d forgotten to add it to the Home Page since it never showed as a problem for us - d’oh!

Thanks so much again :clap:

Glad to hear it got sorted!

1 Like

Fastest bug fix ever. Really appreciate it!

1 Like