|
2 | 2 |
|
3 | 3 | from django_mongodb_backend import parse_uri |
4 | 4 |
|
5 | | -PARSED_URI = parse_uri(os.getenv("MONGODB_URI")) if os.getenv("MONGODB_URI") else {} |
| 5 | +if mongodb_uri := os.getenv("MONGODB_URI"): |
| 6 | + db_settings = parse_uri(mongodb_uri) |
6 | 7 |
|
7 | | -# Temporary fix for https://github.com/mongodb-labs/mongo-orchestration/issues/268 |
8 | | -if PARSED_URI.get("USER") and PARSED_URI.get("PASSWORD"): |
9 | | - PARSED_URI["OPTIONS"].update({"tls": True, "tlsAllowInvalidCertificates": True}) |
10 | | - |
11 | | -DATABASES = { |
12 | | - "default": { |
13 | | - **PARSED_URI, |
14 | | - "ENGINE": "django_mongodb_backend", |
15 | | - "NAME": "djangotests", |
16 | | - }, |
17 | | - "other": { |
18 | | - **PARSED_URI, |
19 | | - "ENGINE": "django_mongodb_backend", |
20 | | - "NAME": "djangotests-other", |
21 | | - }, |
22 | | -} |
| 8 | + # Workaround for https://github.com/mongodb-labs/mongo-orchestration/issues/268 |
| 9 | + if db_settings["USER"] and db_settings["PASSWORD"]: |
| 10 | + db_settings.update({"tls": True, "tlsAllowInvalidCertificates": True}) |
| 11 | + DATABASES = { |
| 12 | + "default": {**db_settings, "NAME": "djangotests"}, |
| 13 | + "other": {**db_settings, "NAME": "djangotests-other"}, |
| 14 | + } |
| 15 | +else: |
| 16 | + DATABASES = { |
| 17 | + "default": { |
| 18 | + "ENGINE": "django_mongodb_backend", |
| 19 | + "NAME": "djangotests", |
| 20 | + }, |
| 21 | + "other": { |
| 22 | + "ENGINE": "django_mongodb_backend", |
| 23 | + "NAME": "djangotests-other", |
| 24 | + }, |
| 25 | + } |
23 | 26 |
|
24 | 27 | DEFAULT_AUTO_FIELD = "django_mongodb_backend.fields.ObjectIdAutoField" |
25 | 28 | PASSWORD_HASHERS = ("django.contrib.auth.hashers.MD5PasswordHasher",) |
|
0 commit comments