From 3f18bfc67aa40797d68745d5ea26a369b6c97ae9 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Tue, 24 Nov 2020 19:41:38 -0500 Subject: [PATCH] Retry in the case of failures. #1010 PyPy seems prone to intermittent SQLite failures. An immediate retry avoids them. Not great, but it works. --- CHANGES.rst | 5 +++++ coverage/sqldata.py | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 52fd6645e..800ab2cf4 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -27,9 +27,14 @@ Unreleased - When using ``--source`` on a large source tree, v5.x was slower than previous versions. This performance regression is now fixed, closing `issue 1037`_. +- Mysterious SQLite errors can happen on PyPy, as reported in `issue 1010`_. An + immediate retry seems to fix the problem, although it is an unsatisfying + solution. + - Continuous integration has moved from Travis and AppVeyor to GitHub Actions. .. _issue 1037: https://github.com/nedbat/coveragepy/issues/1037 +.. _issue 1010: https://github.com/nedbat/coveragepy/issues/1010 .. _changes_53: diff --git a/coverage/sqldata.py b/coverage/sqldata.py index 702bd42b9..7a3b5c795 100644 --- a/coverage/sqldata.py +++ b/coverage/sqldata.py @@ -1056,7 +1056,13 @@ def execute(self, sql, parameters=()): tail = " with {!r}".format(parameters) if parameters else "" self.debug.write("Executing {!r}{}".format(sql, tail)) try: - return self.con.execute(sql, parameters) + try: + return self.con.execute(sql, parameters) + except Exception: + # In some cases, an error might happen that isn't really an + # error. Try again immediately. + # https://github.com/nedbat/coveragepy/issues/1010 + return self.con.execute(sql, parameters) except sqlite3.Error as exc: msg = str(exc) try: