safe handling for mediaType in confluence connector in all places (#4269)

Co-authored-by: Richard Kuo (Danswer) <rkuo@onyx.app>
This commit is contained in:
rkuo-danswer 2025-03-12 23:09:19 -07:00 committed by GitHub
parent a2ac9f02fb
commit b4ecc870b9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -301,7 +301,7 @@ def convert_attachment_to_content(
2. Extracts content or stores image for later processing
3. Returns (content_text, stored_file_name) or None if we should skip it
"""
media_type = attachment["metadata"]["mediaType"]
media_type = attachment.get("metadata", {}).get("mediaType", "")
# Quick check for unsupported types:
if media_type.startswith("video/") or media_type == "application/gliffy+json":
logger.warning(
@ -522,6 +522,10 @@ def attachment_to_file_record(
download_link, absolute=True, not_json_response=True
)
file_type = attachment.get("metadata", {}).get(
"mediaType", "application/octet-stream"
)
# Save image to file store
file_name = f"confluence_attachment_{attachment['id']}"
lobj_oid = create_populate_lobj(BytesIO(image_data), db_session)
@ -529,7 +533,7 @@ def attachment_to_file_record(
file_name=file_name,
display_name=attachment["title"],
file_origin=FileOrigin.OTHER,
file_type=attachment["metadata"]["mediaType"],
file_type=file_type,
lobj_oid=lobj_oid,
db_session=db_session,
commit=True,