Skip to content

Commit

Permalink
fix(project,handlers): ignore signals at project create
Browse files Browse the repository at this point in the history
Signed-off-by: David Wallace <[email protected]>
  • Loading branch information
MyPyDavid committed Jan 22, 2025
1 parent edb842e commit ca40992
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion rdmo/projects/handlers/project_save_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

@receiver(pre_save, sender=Project)
def pre_save_project_sync_tasks_from_catalog(sender, instance, raw, update_fields, **kwargs):
if raw or (update_fields and 'catalog' not in update_fields):
if (raw or
instance.id is None or
(update_fields and 'catalog' not in update_fields)
):
return

# Fetch the original catalog from the database
Expand All @@ -22,6 +25,8 @@ def pre_save_project_sync_tasks_from_catalog(sender, instance, raw, update_field

@receiver(post_save, sender=Project)
def post_save_project_sync_tasks_from_catalog(sender, instance, created, raw, **kwargs):
if not hasattr(instance, DEFERRED_SYNC_TASKS_KEY):
return
if getattr(instance, DEFERRED_SYNC_TASKS_KEY, None) or (created and not raw):
# For existing projects with catalog changes, use deferred views
instance.views.set(Task.objects.filter_available_tasks_for_project(instance))
Expand Down
7 changes: 6 additions & 1 deletion rdmo/projects/handlers/project_save_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

@receiver(pre_save, sender=Project)
def pre_save_project_sync_views_from_catalog(sender, instance, raw, update_fields, **kwargs):
if raw or (update_fields and 'catalog' not in update_fields):
if (raw or
instance.id is None or
(update_fields and 'catalog' not in update_fields)
):
return

# Fetch the original catalog from the database
Expand All @@ -22,6 +25,8 @@ def pre_save_project_sync_views_from_catalog(sender, instance, raw, update_field

@receiver(post_save, sender=Project)
def post_save_project_sync_views_from_catalog(sender, instance, created, raw, update_fields, **kwargs):
if not hasattr(instance, DEFERRED_SYNC_VIEWS_KEY):
return
if getattr(instance, DEFERRED_SYNC_VIEWS_KEY, None) or (created and not raw):
# For existing projects with catalog changes, use deferred views
instance.views.set(View.objects.filter_available_views_for_project(instance))
Expand Down

0 comments on commit ca40992

Please sign in to comment.