From 0b10ba79735951883058f1423488f690de0cf076 Mon Sep 17 00:00:00 2001 From: Lada Tesarik Date: Sun, 1 Nov 2020 11:55:51 +0100 Subject: [PATCH] Prevention of accidental setting of parameter to its default value - https://github.com/jazzband/django-constance/issues/348 --- constance/backends/database/__init__.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/constance/backends/database/__init__.py b/constance/backends/database/__init__.py index 454b5001..992cbb41 100644 --- a/constance/backends/database/__init__.py +++ b/constance/backends/database/__init__.py @@ -3,6 +3,7 @@ from django.core.exceptions import ImproperlyConfigured from django.db import OperationalError, ProgrammingError from django.db.models.signals import post_save +from sentry_sdk import capture_exception from .. import Backend from ... import settings, signals, config @@ -73,8 +74,8 @@ def get(self, key): if value is None: try: value = self._model._default_manager.get(key=key).value - except (OperationalError, ProgrammingError, self._model.DoesNotExist): - pass + except (self._model.DoesNotExist) as e: + capture_exception(e) else: if self._cache: self._cache.add(key, value) @@ -83,13 +84,9 @@ def get(self, key): def set(self, key, value): old_value = self.get(key) - try: - constance, created = self._model._default_manager.get_or_create( - key=self.add_prefix(key), defaults={'value': value} - ) - except (OperationalError, ProgrammingError): - # database is not created, noop - return + constance, created = self._model._default_manager.get_or_create( + key=self.add_prefix(key), defaults={'value': value} + ) if not created: constance.value = value