Skip to content

signals.py

Functions that are executed upon receiving an application signal.

delete_orphans_for_run(sender, instance, using, **kwargs)

Delete any Image and SkyRegion objects that would be orphaned by deleting the given Run. Expects to recieve the arguments sent by the pre_delete signal. See https://docs.djangoproject.com/en/3.1/ref/signals/#pre-delete.

Parameters:

Name Type Description Default
sender Type[Run]

Model class that sent the signal.

required
instance Run

Model instance to be deleted.

required
using str

Database alias.

required

Returns:

Type Description
None

None

Source code in vast_pipeline/signals.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
@receiver(pre_delete, sender=Run, dispatch_uid="delete_orphans_for_run")
def delete_orphans_for_run(sender: Type[Run], instance: Run, using: str, **kwargs) -> None:
    """Delete any Image and SkyRegion objects that would be orphaned by deleting the
    given Run. Expects to recieve the arguments sent by the pre_delete signal. See
    <https://docs.djangoproject.com/en/3.1/ref/signals/#pre-delete>.

    Args:
        sender:
            Model class that sent the signal.
        instance:
            Model instance to be deleted.
        using:
            Database alias.

    Returns:
        None
    """
    image_orphans = (
        Image.objects.annotate(num_runs=Count("run"))
        .filter(run=instance, num_runs=1)
    )
    n_obj_deleted, deleted_dict = image_orphans.delete()
    logger.info(
        "Deleted %d objects: %s",
        n_obj_deleted,
        ", ".join([f"{model}: {n}" for model, n in deleted_dict.items()]),
    )

    skyreg_orphans = (
        SkyRegion.objects.annotate(num_runs=Count("run"))
        .filter(run=instance, num_runs=1)
    )
    n_obj_deleted, deleted_dict = skyreg_orphans.delete()
    logger.info(
        "Deleted %d objects: %s",
        n_obj_deleted,
        ", ".join([f"{model}: {n}" for model, n in deleted_dict.items()]),
    )