Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1802,7 +1802,9 @@ async def unit_of_work(txn, *args, **kw):

# retry once w/ timeout_secs=1
def _time(_results=[1, 1.5]):
return _results.pop(0)
if len(_results) > 1:
return _results.pop(0)
return _results[0]
Comment on lines +1805 to +1807
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current implementation of the _time mock helper is fragile as it assumes _results will always contain at least one element. While the default value provides this, an empty list passed explicitly would still cause an IndexError. To ensure fail-fast behavior and prevent potential issues with missing values, the function should raise a ProgrammingError if the list is empty instead of returning a default value.

Suggested change
if len(_results) > 1:
return _results.pop(0)
return _results[0]
if not _results:
raise ProgrammingError('No time results provided')
if len(_results) > 1:
return _results.pop(0)
return _results[0]
References
  1. When a function receives parameters of an unsupported type, it should raise an error (e.g., ProgrammingError) instead of silently returning empty values. This ensures fail-fast behavior and prevents potential issues with missing parameter values in database operations.


with mock.patch("time.time", _time):
with mock.patch(
Expand Down
Loading