gtalarico / pyairtable

Python Api Client for Airtable
https://pyairtable.readthedocs.io
MIT License
765 stars 138 forks source link

Key error fields with batch_upsert #271

Closed simonkatz88 closed 1 year ago

simonkatz88 commented 1 year ago

When, I try to use batch_upsert, I keep getting a key error when the table tries to get the fields.


KeyError Traceback (most recent call last) File :9 7 #data = {"records": []} 8 for chunk in all_records: ----> 9 table.batch_upsert(chunk,key_fields) File /local_disk0/.ephemeral_nfs/envs/pythonEnv-1ca7f691-7760-4b49-87ff-cfd3c10c673e/lib/python3.10/site-packages/pyairtable/api/table.py:181, in Table.batch_upsert(self, records, key_fields, replace, typecast, return_fields_by_field_id) 169 def batch_upsert( 170 self, 171 records: List[dict], (...) 175 return_fields_by_field_id=False, 176 ): 177 """ 178 Same as :meth:Api.batch_upsert <pyairtable.api.Api.batch_upsert> 179 but without base_id and table_name arg. 180 """ --> 181 return super()._batch_upsert( 182 self.base_id, 183 self.table_name, 184 records, 185 key_fields=key_fields, 186 replace=replace, 187 typecast=typecast, 188 return_fields_by_field_id=return_fields_by_field_id, 189 ) File /local_disk0/.ephemeral_nfs/envs/pythonEnv-1ca7f691-7760-4b49-87ff-cfd3c10c673e/lib/python3.10/site-packages/pyairtable/api/abstract.py:311, in ApiAbstract._batch_upsert(self, base_id, table_name, records, key_fields, replace, typecast, return_fields_by_field_id) 309 missing = set(key_fields) - set(record.get("fields", [])) 310 if missing: --> 311 raise ValueError(f"missing {missing!r} in {record['fields'].keys()!r}") 313 updated_records = [] 314 table_url = self.get_table_url(base_id, table_name) KeyError: 'fields'