Skip to content

Commit

Permalink
another airtable fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Weves committed Feb 3, 2025
1 parent 87bccc1 commit 68f39af
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions backend/onyx/connectors/airtable/airtable_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def airtable_client(self) -> AirtableApi:
def _extract_field_values(
self,
field_id: str,
field_name: str,
field_info: Any,
field_type: str,
base_id: str,
Expand Down Expand Up @@ -133,19 +134,23 @@ def get_attachment_with_retry(url: str, record_id: str) -> bytes | None:
return attachment_response.content
except requests.exceptions.HTTPError as e:
if e.response.status_code == 410:
logger.info(f"Refreshing attachment for {filename}")
# Re-fetch the record to get a fresh URL
refreshed_record = self.airtable_client.table(
base_id, table_id
).get(record_id)
for refreshed_attachment in refreshed_record["fields"].get(
field_id, []
):
for refreshed_attachment in refreshed_record["fields"][
field_name
]:
if refreshed_attachment.get("filename") == filename:
new_url = refreshed_attachment.get("url")
if new_url:
attachment_response = requests.get(new_url)
attachment_response.raise_for_status()
return attachment_response.content

logger.error(f"Failed to refresh attachment for {filename}")

raise

attachment_content = get_attachment_with_retry(url, record_id)
Expand Down Expand Up @@ -232,6 +237,7 @@ def _process_field(
# Get the value(s) for the field
field_value_and_links = self._extract_field_values(
field_id=field_id,
field_name=field_name,
field_info=field_info,
field_type=field_type,
base_id=self.base_id,
Expand Down

0 comments on commit 68f39af

Please sign in to comment.