Skip to content

Commit

Permalink
[BUGFIX] Fix handling of kwargs in skip_raw decorator #396
Browse files Browse the repository at this point in the history
When calling post_save with Service, we call out to save_project, but did not handle some of our required parameters correctly

- Change functions to all kwargs to hopefully catch errors in the future
- Default raw=False in our wrapper to match post_save.send
  • Loading branch information
kfdm authored Jun 14, 2022
2 parents fbbc2fe + 5c0b6c3 commit d016c31
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions promgen/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ def skip_raw(func):
"""

@wraps(func)
def _wrapper(*args, raw, instance, **kwargs):
def _wrapper(*, raw=False, instance, **kwargs):
if raw:
logger.debug("Skipping %s:%s for raw %s", __name__, func.__name__, instance)
return
logger.debug("Running %s:%s for %s", __name__, func.__name__, instance)
return func(*args, raw=raw, instance=instance, **kwargs)
return func(raw=raw, instance=instance, **kwargs)

return _wrapper

Expand Down Expand Up @@ -230,17 +230,19 @@ def delete_project(sender, instance, **kwargs):

@receiver(post_save, sender=models.Service)
@skip_raw
def save_service(instance, **kwargs):
def save_service(*, sender, instance, **kwargs):
# We saving a service, we delegate the configuration reload triggering to
# the child projects which have additional information about if we need to
# write out our file or not. We call our save_project signal directly
# (instead of through post_save.save) because we don't want to trigger other
# attached signals
# We don't use sender here, but put it in our parameters so we don't pass
# two sender entries to save_project
for project in instance.project_set.prefetch_related(
'farm',
'farm__host_set',
'exporter_set'):
if save_project(sender=models.Project, instance=project):
if save_project(sender=models.Project, instance=project, **kwargs):
# If any of our save_project returns True, then we do not need to
# check any others
return True
Expand Down

0 comments on commit d016c31

Please sign in to comment.