Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add database router to fix false positives on relation mismatch. (#10524)

Dominik Kozaczko2de76e2cec57
diff --git a/saleor/core/db_routers.py b/saleor/core/db_routers.py
new file mode 100644
index 0000000000..9f93c65a71
--- /dev/null
+++ b/saleor/core/db_routers.py
@@ -0,0 +1,11 @@
+from django.conf import settings
+
+
+class PrimaryReplicaRouter:
+ def db_for_write(self, model, **hints):
+ """Write only to primary."""
+ return settings.DATABASE_CONNECTION_DEFAULT_NAME
+
+ def allow_relation(self, obj1, obj2, **hints):
+ """All relations are allowed as we don't have pool separation."""
+ return True
diff --git a/saleor/settings.py b/saleor/settings.py
index 33674873f6..adea46621b 100644
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -89,6 +89,8 @@ DATABASES = {
# ),
}
+DATABASE_ROUTERS = ["saleor.core.db_routers.PrimaryReplicaRouter"]
+
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
TIME_ZONE = "UTC"