diff --git a/hobo/environment/management/commands/cook.py b/hobo/environment/management/commands/cook.py index 503fa6e..d44fd98 100644 --- a/hobo/environment/management/commands/cook.py +++ b/hobo/environment/management/commands/cook.py @@ -172,23 +172,34 @@ class Command(BaseCommand): def create_site(self, klass, base_url, title, slug, template_name, variables): if slug is None: slug = klass.Extra.service_default_slug - obj, must_save = klass.objects.get_or_create( - slug=slug, defaults={'title': title, 'base_url': base_url, 'template_name': template_name} - ) + + try: + obj = klass.objects.get(slug=slug) + must_save = False + except klass.DoesNotExist: + obj = klass(slug=slug) + must_save = True + for attr in ('title', 'base_url', 'template_name'): if getattr(obj, attr) != locals().get(attr): setattr(obj, attr, locals().get(attr)) must_save = True - if must_save: - try: - obj.full_clean( - exclude=['last_operational_success_timestamp', 'last_operational_check_timestamp'] - ) - except ValidationError as e: - raise CommandError(str(e)) + try: + obj.full_clean( + exclude=[ + 'secret_key', + 'last_operational_success_timestamp', + 'last_operational_check_timestamp', + ] + ) + except ValidationError as e: + raise CommandError(str(e)) + + if must_save: obj.save() self.must_notify = True + variables = variables or {} obj_type = ContentType.objects.get_for_model(klass) for variable_name in variables.keys():