Handle SQL InvalidRequestErrors when transferring files

This commit is contained in:
Tulir Asokan
2018-03-07 19:11:23 +02:00
parent 0e6940eea5
commit 7004da9268
+3 -3
View File
@@ -20,7 +20,7 @@ import logging
import magic
from PIL import Image
from sqlalchemy.exc import IntegrityError
from sqlalchemy.exc import IntegrityError, InvalidRequestError
from telethon_aio.tl.types import (Document, FileLocation, InputFileLocation,
InputDocumentFileLocation, PhotoCachedSize)
@@ -73,9 +73,9 @@ async def transfer_file_to_matrix(db, client, intent, location):
try:
db.add(db_file)
db.commit()
except IntegrityError:
except (IntegrityError, InvalidRequestError) as e:
db.rollback()
log.exception("Integrity error while saving transferred file data. "
log.exception(f"{e.__class__.__name__} while saving transferred file data. "
"This was probably caused by two simultaneous transfers of the same file, "
"and should not cause any problems.")