rtutil: Fix crash when multiple RTLinkCaches race.

This was most likely to happen with multiple bean-checks running in
parallel: they would both see a new RT URL, fetch it, and try to
insert it into the cache. That's not a problem as long as they're
both inserting the same URL, so catch that exception.
This commit is contained in:
Brett Smith 2020-08-30 11:18:32 -04:00
parent dc2e2d200d
commit 0e52f11a58

View file

@ -171,10 +171,16 @@ class RTLinkCache(_LinkCache):
self._nourls.add(key)
else:
ticket_id, attachment_id = key
try:
self._db.execute(
'INSERT INTO RTLinkCache VALUES(?, ?, ?)',
(ticket_id, attachment_id, value),
)
except sqlite3.IntegrityError:
# Another instance might've inserted the URL before we did.
# That's fine as long as it's the same URL, which it should be.
if value != self.get(key):
raise
def __delitem__(self, key: TicketAttachmentIds) -> None:
raise NotImplementedError("RTLinkCache.__delitem__")