Refactor more code

This commit is contained in:
Tulir Asokan
2018-02-23 21:24:18 +02:00
parent 9e5843a0dc
commit 9e5cb84140
3 changed files with 30 additions and 17 deletions
+8 -2
View File
@@ -20,6 +20,7 @@ import logging
import magic
from PIL import Image
from sqlalchemy.exc import IntegrityError
from telethon.tl.types import (Document, FileLocation, InputFileLocation,
InputDocumentFileLocation)
@@ -69,7 +70,12 @@ async def transfer_file_to_matrix(db, client, intent, location):
db_file = DBTelegramFile(id=id, mxc=uploaded["content_uri"],
mime_type=mime_type, was_converted=image_converted,
timestamp=int(time.time()))
db.add(db_file)
db.commit()
try:
db.add(db_file)
db.commit()
except IntegrityError:
log.exception("Integrity error while saving transferred file data. "
"This was probably caused by two simultaneous transfers of the same file, "
"and should not cause any problems.")
return db_file