Skip to content

Commit c1fb3f9

Browse files
committed
Add db_for_read, db_for_write to encrypted router
1 parent 7b0956d commit c1fb3f9

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

.github/workflows/mongodb_settings.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from pymongo.uri_parser import parse_uri
44

5+
from django_mongodb_backend.utils import model_has_encrypted_fields
6+
57
if mongodb_uri := os.getenv("MONGODB_URI"):
68
db_settings = {
79
"ENGINE": "django_mongodb_backend",
@@ -34,6 +36,13 @@
3436

3537

3638
class EncryptedRouter:
39+
def db_for_read(self, model, **hints):
40+
if model_has_encrypted_fields(model):
41+
return "encrypted"
42+
return "default"
43+
44+
db_for_write = db_for_read
45+
3746
def allow_migrate(self, db, app_label, model_name=None, **hints):
3847
# The encryption_ app's models are only created in the encrypted
3948
# database.

0 commit comments

Comments
 (0)