Commit 77524106 authored by lukas.burgey's avatar lukas.burgey

Simplify DeploymentState.get_or_create

parent 151380fb
......@@ -418,32 +418,22 @@ class DeploymentState(models.Model):
@classmethod
def get_or_create(cls, user, service, deployment):
try:
state, created = cls.objects.get_or_create(
user=user,
site=service.site,
service=service,
defaults={
'userinfo': user.userinfo,
'service_name': service.name,
}
)
if created:
LOGGER.debug(state.msg('Created'))
# always bind this state to the deployment
state.bind_to_deployment(deployment)
state, created = cls.objects.get_or_create(
user=user,
service=service,
defaults={
'userinfo': user.userinfo,
'service_name': service.name,
'site': service.site,
}
)
if created:
LOGGER.debug(state.msg('Created'))
return state, created
# always bind this state to the deployment
state.bind_to_deployment(deployment)
except cls.MultipleObjectsReturned:
LOGGER.error(
'Multiple DeploymentStates for %s and %s and %s',
user,
service,
deployment,
)
return None, False
return state, created
# adds the deployment to our related deployments
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment