From eaae84431f8150c252f366c5d14021e4c0807d1c Mon Sep 17 00:00:00 2001 From: dzen Date: Tue, 13 Oct 2020 10:07:38 +0200 Subject: [PATCH] router: disallow migrations on ldap connection and models --- ldapdb/router.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ldapdb/router.py b/ldapdb/router.py index 60ff211..fddb881 100644 --- a/ldapdb/router.py +++ b/ldapdb/router.py @@ -2,6 +2,10 @@ # This software is distributed under the two-clause BSD license. # Copyright (c) The django-ldapdb project +from django.apps import apps + +from ldapdb.models import Model + def is_ldap_model(model): # FIXME: there is probably a better check than testing 'base_dn' @@ -27,8 +31,15 @@ def __init__(self): break def allow_migrate(self, db, app_label, model_name=None, **hints): - if 'model' in hints and is_ldap_model(hints['model']): + # disallow any migration operation on ldap engine + if db == self.ldap_alias: return False + + # avoid any migration operation on ldap models + if model_name: + model = apps.get_model(app_label, model_name) + if issubclass(model, Model): + return False return None def db_for_read(self, model, **hints):