From 7c4cf10318242a703112572ed3e7469f1d48deba Mon Sep 17 00:00:00 2001 From: Jannik Eilers Date: Mon, 10 Feb 2025 15:32:51 +0100 Subject: [PATCH 1/2] 943 MSSQL POC --- .../management/commands/clean_duplicate_history.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/simple_history/management/commands/clean_duplicate_history.py b/simple_history/management/commands/clean_duplicate_history.py index 786be6a11..9ba528749 100644 --- a/simple_history/management/commands/clean_duplicate_history.py +++ b/simple_history/management/commands/clean_duplicate_history.py @@ -93,7 +93,18 @@ def _process(self, to_process, date_back=None, dry_run=True): pk__in=(m_qs.values_list(model._meta.pk.name).distinct()) ) - for o in model_query.iterator(): + def get_backend_name(model_class): + from django.db import connections, router + db_alias = router.db_for_read(model_class) + return connections[db_alias].vendor + + backend_name = get_backend_name(model) + if backend_name != 'microsoft': + _iterator = model_query.iterator() + else: + _iterator = model_query + + for o in _iterator: self._process_instance(o, model, stop_date=stop_date, dry_run=dry_run) def _process_instance(self, instance, model, stop_date=None, dry_run=True): From 769846db6b5008a396055a5595d7d4b6988a7702 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 10 Feb 2025 14:42:45 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- simple_history/management/commands/clean_duplicate_history.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/simple_history/management/commands/clean_duplicate_history.py b/simple_history/management/commands/clean_duplicate_history.py index 9ba528749..b5a7d8688 100644 --- a/simple_history/management/commands/clean_duplicate_history.py +++ b/simple_history/management/commands/clean_duplicate_history.py @@ -95,11 +95,12 @@ def _process(self, to_process, date_back=None, dry_run=True): def get_backend_name(model_class): from django.db import connections, router + db_alias = router.db_for_read(model_class) return connections[db_alias].vendor backend_name = get_backend_name(model) - if backend_name != 'microsoft': + if backend_name != "microsoft": _iterator = model_query.iterator() else: _iterator = model_query