Skip to content

Commit

Permalink
CoverageSqliteData._file_id: fall back to SELECT
Browse files Browse the repository at this point in the history
Fixes #702
  • Loading branch information
blueyed committed Oct 23, 2018
1 parent 6c14ffb commit 1fec608
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions coverage/sqldata.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,16 @@ def _file_id(self, filename, add=False):
if filename not in self._file_map:
if add:
with self._connect() as con:
cur = con.execute("insert into file (path) values (?)", (filename,))
self._file_map[filename] = cur.lastrowid
try:
cur = con.execute("insert into file (path) values (?)", (filename,))
except CoverageException as exc:
if "UNIQUE constraint failed: file.path" in str(exc):
cur = self._db.execute("select id from file where path = (?)", (filename,))
self._file_map[filename] = cur.fetchone()[0]
else:
raise
else:
self._file_map[filename] = cur.lastrowid
return self._file_map.get(filename)

def _context_id(self, context):
Expand Down

0 comments on commit 1fec608

Please sign in to comment.