Skip to content

Commit 4bac595

Browse files
committed
fix mongodb engine check
models.py line 315 `if settings.DATABASES[connection]['ENGINE'] in ('django_mongodb_engine',):` can throw a KeyError if the project configuration does not follow Django docs guidelines for setup Legacy projects can potentially have a working Django app set up like this: ```python DATABASES = { 'default': dj_config_url.config(env='DATABASE_URL'), 'alternative': dj_config_url.config(env='ALTERNATIVE_DATABASE_URL'), } ``` Considering that during a migration for simple_history, models.py checks for a key that does not exist, an exception is thrown that prevents the project from running.
1 parent b01b92c commit 4bac595

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

simple_history/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ def convert_auto_field(field):
312312
must be replaced with an IntegerField.
313313
"""
314314
connection = router.db_for_write(field.model)
315-
if settings.DATABASES[connection]['ENGINE'] in ('django_mongodb_engine',):
315+
if settings.DATABASES[connection].get('ENGINE') in ('django_mongodb_engine',):
316316
# Check if AutoField is string for django-non-rel support
317317
return models.TextField
318318
return models.IntegerField

0 commit comments

Comments
 (0)