From 5fb1bbbe4d18e2e3019543804bcd040feee7b62e Mon Sep 17 00:00:00 2001 From: helgi Date: Wed, 8 Jun 2016 11:20:50 -0700 Subject: [PATCH] fix(config): when rolling a new config copy from the latest release instead of latest config for the app This helps mitigate #798 for day to day use (quick fix) as the previous config is no longer pulled from the top of the application config stack and instead pulls the latest release config. Doing that will prevent the logic from re-using a potentially broken Config object. When a Release object is deleted an Config object can be orphaned but still available. --- rootfs/api/models/config.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/rootfs/api/models/config.py b/rootfs/api/models/config.py index 1294bb94c..ae6f45081 100644 --- a/rootfs/api/models/config.py +++ b/rootfs/api/models/config.py @@ -2,6 +2,7 @@ from django.db import models from jsonfield import JSONField +from api.models.release import Release from api.models import UuidAuditedModel, DeisException @@ -110,7 +111,14 @@ def set_tags(self, previous_config): def save(self, **kwargs): """merge the old config with the new""" try: - previous_config = self.app.config_set.latest() + # Get config from the latest available release + try: + previous_config = self.app.release_set.latest().config + except Release.DoesNotExist: + # If that doesn't exist then fallback on app config + # usually means a totally new app + previous_config = self.app.config_set.latest() + for attr in ['cpu', 'memory', 'tags', 'registry', 'values']: data = getattr(previous_config, attr, {}).copy() new_data = getattr(self, attr, {}).copy()