From fb880f00751757375d560432872bf9012fc9fac0 Mon Sep 17 00:00:00 2001 From: Ben Stockermans Date: Tue, 5 Aug 2025 16:45:18 +0100 Subject: [PATCH] Added a check for instance._state.adding to instance_pre_save as checking not instance.pk is insufficient. It can have a PK but not be saved in the DB yet, which will call this to fail. --- linkcheck/listeners.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linkcheck/listeners.py b/linkcheck/listeners.py index f82784f..0642aeb 100644 --- a/linkcheck/listeners.py +++ b/linkcheck/listeners.py @@ -132,7 +132,7 @@ def delete_instance_links(sender, instance, **kwargs): def instance_pre_save(sender, instance, raw=False, **kwargs): - if not instance.pk or raw: + if instance._state.adding or not instance.pk or raw: # Ignore unsaved instances or raw imports return current_url = instance.get_absolute_url()