From e0bb5a575fa0c1157d42a5fcd480fe56d14f7cd5 Mon Sep 17 00:00:00 2001 From: av <65823953+arthur-verta@users.noreply.github.com> Date: Mon, 23 Dec 2024 16:53:31 -0500 Subject: [PATCH 1/2] Update utils.py Make sure that the cache key pk used, if any available, is converted to INT format. --- django_pandas/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django_pandas/utils.py b/django_pandas/utils.py index 0778f9d..f3fc978 100644 --- a/django_pandas/utils.py +++ b/django_pandas/utils.py @@ -44,7 +44,7 @@ def replace_pk(model): base_cache_key = get_base_cache_key(model) def get_cache_key_from_pk(pk): - return None if pk is None else base_cache_key % str(pk) + return None if pk is None else base_cache_key % str(int(pk)) def inner(pk_series): pk_series = pk_series.astype(object).where(pk_series.notnull(), None) From fdfe404ea6f06b6e57a754c8c1a2032a6e8c2def Mon Sep 17 00:00:00 2001 From: av <65823953+arthur-verta@users.noreply.github.com> Date: Mon, 23 Dec 2024 17:09:48 -0500 Subject: [PATCH 2/2] Update utils.py Add a try / except, in case the orginial pk is not an integer --- django_pandas/utils.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/django_pandas/utils.py b/django_pandas/utils.py index f3fc978..59d177c 100644 --- a/django_pandas/utils.py +++ b/django_pandas/utils.py @@ -44,7 +44,13 @@ def replace_pk(model): base_cache_key = get_base_cache_key(model) def get_cache_key_from_pk(pk): - return None if pk is None else base_cache_key % str(int(pk)) + if pk is None: + return None + else: + try: + return base_cache_key % str(int(pk)) + except: + return base_cache_key % str(pk) def inner(pk_series): pk_series = pk_series.astype(object).where(pk_series.notnull(), None)