From 51ee064965b2d871e31881bdc30afaa223ff4169 Mon Sep 17 00:00:00 2001 From: Matthew McKenzie Date: Wed, 11 Dec 2024 17:11:12 +0000 Subject: [PATCH] PR comment --- workbaskets/models.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/workbaskets/models.py b/workbaskets/models.py index 5de32fe94..674265df9 100644 --- a/workbaskets/models.py +++ b/workbaskets/models.py @@ -560,11 +560,12 @@ def new_transaction(self, **kwargs): if "composite_key" not in kwargs: # Forms a composite key of a zero-padded 5 digit workbasket id + a randomly generated hexadecimal 11 character string. # The probability of a collision is miniscule. It becomes 1% around 600,000 transactions and likely (>50%) at around 5 million. - workbasket_pk = str(self.pk).zfill(5) - if len(workbasket_pk) > 5: + if len(str(self.pk)) > 5: raise ValueError( "Workbasket PK cannot be bigger than 5 digits for composite_key generation.", ) + workbasket_pk = str(self.pk).zfill(5) + hex_string_11_digit = f"{urandom(6).hex()}"[:11] kwargs["composite_key"] = f"{workbasket_pk}{hex_string_11_digit}"