From e6bd1541162531b457f4b52d0037c365e20b8c3e Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Sat, 19 Sep 2020 14:00:06 +0200 Subject: [PATCH] Fix : This is not a rw operation but a ro for db routers --- preferences/models.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/preferences/models.py b/preferences/models.py index 68b8286c..4be70fa7 100644 --- a/preferences/models.py +++ b/preferences/models.py @@ -54,7 +54,9 @@ class PreferencesModel(models.Model): @classmethod def set_in_cache(cls): """Save the preferences in a server-side cache.""" - instance, _created = cls.objects.get_or_create() + instance = cls.objects.first() + if not instance: + instance, _created = cls.objects.get_or_create() cache.set(cls().__class__.__name__.lower(), instance, None) return instance