From 1849f0130a6ae631b59160b6bab97f0fc9d68dd1 Mon Sep 17 00:00:00 2001 From: fredkingham Date: Thu, 18 May 2023 22:37:16 +0100 Subject: [PATCH] Fix a bugin create_random_data It was possible for the date_generator to error with "ValueError: empty range for randrange()". For a leap year the chance was approximately 1 in 12*88 although this changes with date. This happened when the start date integer entered into random.randint was after the end date integer. This change makes that chance impossible. --- changelog.md | 3 +++ opal/management/commands/create_random_data.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index efa981e06..46a4928f4 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,8 @@ ### 0.24.0 (Major Release) +#### Fixes a sporadic failure in create_random_data +Fixes a bug where in an edge case create_random.data.date_generator would raise "ValueError: empty range for randrange()". + ### 0.23.0 (Major Release) #### Enhanced customisation of search results diff --git a/opal/management/commands/create_random_data.py b/opal/management/commands/create_random_data.py index e2af754e5..f9b786d84 100644 --- a/opal/management/commands/create_random_data.py +++ b/opal/management/commands/create_random_data.py @@ -100,7 +100,7 @@ def date_generator(*args, **kwargs): else: first_day = 1 - if first_day == last_day: + if first_day >= last_day: day = first_day else: day = random.randint(first_day, last_day)