Skip to content

Commit

Permalink
handling multipleObjectsReturned on get_or_create_healthcheck funcion
Browse files Browse the repository at this point in the history
  • Loading branch information
henriquebonadio-zz committed May 21, 2015
1 parent c3a7865 commit f9cd309
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion networkapi/api_pools/facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# limitations under the License.

from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
from django.db import transaction

from networkapi.api_pools import exceptions
Expand Down Expand Up @@ -44,12 +44,22 @@ def get_or_create_healthcheck(user, healthcheck_expect, healthcheck_type, health
else:
hc = Healthcheck.objects.get(identifier=identifier, healthcheck_expect=healthcheck_expect, healthcheck_type=healthcheck_type,
healthcheck_request=healthcheck_request, destination=healthcheck_destination)

# Else, add a new one
except ObjectDoesNotExist:
hc = Healthcheck(identifier=identifier, healthcheck_type=healthcheck_type, healthcheck_request=healthcheck_request,
healthcheck_expect=healthcheck_expect, destination=healthcheck_destination)
hc.save(user)

#Get the fisrt occureny and warn if redundant HCs are present
except MultipleObjectsReturned:
if identifier == '':
hc = Healthcheck.objects.filter(healthcheck_expect=healthcheck_expect, healthcheck_type=healthcheck_type,
healthcheck_request=healthcheck_request, destination=healthcheck_destination).order_by('id')[0]
else:
hc = Healthcheck.objects.filter(identifier=identifier, healthcheck_expect=healthcheck_expect, healthcheck_type=healthcheck_type,
healthcheck_request=healthcheck_request, destination=healthcheck_destination).order_by('id')[0]

return hc

def save_server_pool(user, id, identifier, default_port, hc, env, balancing, maxconn, id_pool_member):
Expand Down

0 comments on commit f9cd309

Please sign in to comment.