Skip to content

Commit

Permalink
fix(apis_metainfo): check for numeric id before listing related Uris
Browse files Browse the repository at this point in the history
Some model instance don't have a primary key thats called `id` or don't
have a numeric primary key. Use the `pk` attribute and check if its an
integer before using it to filter Uris.
  • Loading branch information
b1rger committed Jan 10, 2025
1 parent ba58289 commit c5fedd6
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions apis_core/apis_metainfo/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
@receiver(post_delete)
def remove_stale_uris(sender, instance, *args, **kwargs):
content_type = ContentType.objects.get_for_model(instance)
uris = Uri.objects.filter(content_type=content_type, object_id=instance.id)
for uri in uris:
logger.info(
"Deleting uri %s as a result of deleting %s", repr(uri), repr(instance)
)
uri.delete()
if isinstance(instance.pk, int):
uris = Uri.objects.filter(content_type=content_type, object_id=instance.pk)
for uri in uris:
logger.info(
"Deleting uri %s as a result of deleting %s", repr(uri), repr(instance)
)
uri.delete()

0 comments on commit c5fedd6

Please sign in to comment.