CORD-2753 fix legacy services not getting their default owner set properly
Change-Id: Icc433a85531b1d86028d21cce59e7a45cc91fbb1
diff --git a/xos/core/models/serviceinstance.py b/xos/core/models/serviceinstance.py
index a4ab59d..00714f2 100644
--- a/xos/core/models/serviceinstance.py
+++ b/xos/core/models/serviceinstance.py
@@ -83,6 +83,15 @@
raise XOSValidationError("Cannot find eligible owner of class %s" % self.OWNER_CLASS_NAME)
self.owner = owners[0]
+ else:
+ # Deal with legacy services that specify their owner as _meta field default. This is a workaround for
+ # what is probably a django bug (if a SerivceInstance without a default is created before a ServiceInstance
+ # that does have a default, then the later service's default is not honored by django).
+
+ # TODO: Delete this after all services have been migrated away from using field defaults
+
+ if (not self.owner_id) and (self._meta.get_field("owner").default):
+ self.owner = Service.objects.get(id = self._meta.get_field("owner").default)
# If the model has a Creator and it's not specified, then attempt to default to the Caller. Caller is
# automatically filled in my the API layer. This code was typically used by ServiceInstances that lead to