Anvil Error: TypeError: 'NoneType' object is not subscriptable

196 views Asked by At

I'm attempting to return a value from a row in my data table, and am getting the following error:

TypeError: 'NoneType' object is not subscriptable (key 'GCWR')

Here is the code snippet which is referenced in the error...

"""
This function gets the GCWR of the truck from the 'truck_specifications' data table
Parameters: brand, model, year, engine, drive, axle
Returns: gcwr
"""
def get_gcwr(brand, model, year, engine, drive, axle):
  gcwr_row = app_tables.truck_specifications.get(Brand=brand, Model=model, Year=year, Engine_Type=engine, Drive_Type=drive, Axle_Ratio=axle)
  gcwr = gcwr_row['GCWR']
  return gcwr

Some details:

  • The variable 'gcwr' should return a number from a specific row in the data table based on the parameters shown above
  • This previously worked, but when I began to add more data to the table it now gives me the error shown above
  • I've manually reviewed the data table based on the parameters, and there is a row that meets the criteria and should return a value
  • The data type for the column in the data table is 'number'

Here is the code snippet which the above function is called from...

"""
This function gets the truck specifications based on the users input
Parameters: none
Returns: value (allowable trailer GVWR)
"""
@anvil.server.callable
def get_truck_specifications():
  
  # Get data from 'truck_inputs' data table
  brand = get_brand()
  model = get_model()
  year = get_year()
  engine = get_engine()
  drive = get_drive()
  axle = get_axle()
  payload = int(get_payload())
  passengers = int(get_passengers())
  cargo = int(get_cargo())
  hitch = int(get_hitch())
  
  # Get data from 'truck_specifications' data table
  gcwr = int(get_gcwr(brand, model, year, engine, drive, axle))
  gvwr_truck = int(get_gvwr_truck(brand, model, year, engine, drive, axle))
  base_weight = int(get_base_weight(gvwr_truck, payload))
  gvw = base_weight + passengers + cargo + hitch
  value = gcwr - gvw
  return value

Here is a screen shot that shows an example of the data table...

'Truck Specifications' data table image

1

There are 1 answers

0
flyguy712 On

It appears that the columns in the data table were not labeled correctly after I implemented an uploader (versus manually adding data). After re-labeling, the problem is solved.