

@transaction.atomic
def _save_environments(self, instance, environments):
    '\n        Save service-environments many-to-many records.\n        '
    ServiceEnvironment.objects.filter(service=instance).exclude(environment__in=environments).delete()
    current_environments = set(ServiceEnvironment.objects.filter(service=instance).values_list('environment_id', flat=True))
    for environment in environments:
        if (environment.id not in current_environments):
            ServiceEnvironment.objects.create(service=instance, environment=environment)

dataset/ETHPy150Open allegro/ralph/src/ralph/assets/api/serializers.py SaveServiceSerializer._save_environments/original