Skip to content

Commit

Permalink
Merge pull request #320 from marks/marks-issue-307
Browse files Browse the repository at this point in the history
Add return_fields_by_field_id to Table.update()
  • Loading branch information
mesozoic authored Nov 27, 2023
2 parents 5b30630 + 27a8100 commit 59534ab
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
8 changes: 7 additions & 1 deletion pyairtable/api/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ def update(
fields: WritableFields,
replace: bool = False,
typecast: bool = False,
return_fields_by_field_id: bool = False,
) -> RecordDict:
"""
Update a particular record ID with the given fields.
Expand All @@ -383,12 +384,17 @@ def update(
fields: Fields to update. Must be a dict with column names or IDs as keys.
replace: |kwarg_replace|
typecast: |kwarg_typecast|
return_fields_by_field_id: |kwarg_return_fields_by_field_id|
"""
method = "put" if replace else "patch"
updated = self.api.request(
method=method,
url=self.record_url(record_id),
json={"fields": fields, "typecast": typecast},
json={
"fields": fields,
"typecast": typecast,
"returnFieldsByFieldId": return_fields_by_field_id,
},
)
return assert_typed_dict(RecordDict, updated)

Expand Down
19 changes: 7 additions & 12 deletions tests/integration/test_integration_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,13 @@ def test_return_fields_by_field_id(table: Table, cols):
record = table.create({cols.TEXT_ID: "Hello"}, return_fields_by_field_id=True)
assert record["fields"][cols.TEXT_ID] == "Hello"

# Updating a record by field ID does not require any special parameters,
# but the return value will have field names (not IDs).
updated = table.update(record["id"], {cols.TEXT_ID: "Goodbye"})
assert updated["fields"][cols.TEXT] == "Goodbye"

# This is not supported (422 Client Error: Unprocessable Entity for url)
# updated = table.update(
# record["id"],
# {cols.TEXT_ID: "Goodbye"},
# return_fields_by_field_id=True,
# )
# assert updated["fields"][cols.TEXT_ID] == "Goodbye"
# Update one record with return_fields_by_field_id=True
updated = table.update(
record["id"],
{cols.TEXT_ID: "Goodbye"},
return_fields_by_field_id=True,
)
assert updated["fields"][cols.TEXT_ID] == "Goodbye"

# Create multiple records with return_fields_by_field_id=True
records = table.batch_create(
Expand Down
1 change: 1 addition & 0 deletions tests/test_orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ def test_linked_record_can_be_saved(requests_mock, access_linked_records):
"Link": [address_id],
},
"typecast": True,
"returnFieldsByFieldId": False,
}


Expand Down

0 comments on commit 59534ab

Please sign in to comment.