May 11, 2024 07:08 PM - edited May 11, 2024 07:09 PM
When I 'get' look-up or select fields using Pyairtable, they're now coming in as list type objects:
'red' is now ['red']
'5/11/24' is now ['5/11/24']
The previous behavior was WYSIWYG. This is unexpected and strange and breaks years worth of ETL scripts that I've built. Anyone else having this problem?
May 15, 2024 02:46 PM - edited May 15, 2024 02:47 PM
Hi Matt! Happy to help out if I can. Can you share your code and the field types and field values as they appear in Airtable for those fields so that we have all the context?
In general, it looks like Pyairtable will return different types of values depending on whether the select field is a single select (returns a single value) or a multi select field (returns a list of values even if the cell value is only one option). For lookup fields, the value is always returned as a list of value even if the cell value is only one option. Here's an illustration and output, hope it helps!
from pyairtable import Api
import os
# Retrieve the Airtable PAT from the environment variable
api_key = os.environ.get('PAT')
# Initialize the Airtable API with the PAT
api = Api(PAT)
# Replace 'appExampleBaseId' and 'tblExampleTableId' with your actual base id and table id
table = api.table('app5qbnCJn5gSbkWq', 'tblFgWntuRbKEJC4n')
# Fetch a single record from the table
record = table.all()[0]
# Get the 'Status' and 'Calories' field values from the record
status = record['fields']['Status'] # single select first run, multiple select second run
calories = record['fields']['Calories'] # lookup field both runs
print(f"Status: {status}")
print(f"Calories: {calories}")
First run of the code when "Status" is a single select field:
Status: Beyond Tasty
Calories: [100]
Second run of the code when "Status" is a multi single select field with multiple option values:
Status: ['Beyond Tasty', 'Okay']
Calories: [100]
Third run of the code when "Status" is a multi single select field with only one option value in the cell:
Status: ['Beyond Tasty']
Calories: [100]