From 19f631fcbc0f244649033b9ae9178437e6743d4a Mon Sep 17 00:00:00 2001 From: Tobias Megies Date: Fri, 31 Jan 2020 14:06:18 +0100 Subject: [PATCH] djangoplugins uniq constraint: use id instead of index was getting error messages about duplicate keys, looks like the id counter is automatically incremented as a uniq field but that index field might not be as a plain integer field (not handled by postgres at all?) --- djangoplugins/management/commands/syncplugins.py | 4 ++-- djangoplugins/migrations/0002_add_id_to_plugins_uniq.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/djangoplugins/management/commands/syncplugins.py b/djangoplugins/management/commands/syncplugins.py index 178daf6..d346a53 100644 --- a/djangoplugins/management/commands/syncplugins.py +++ b/djangoplugins/management/commands/syncplugins.py @@ -107,10 +107,10 @@ def plugins(self, point, point_inst): src = self.get_classes_dict(point.plugins) dst = self.get_instances_dict(point_inst.plugin_set.all()) - for _i, (plugin, inst) in enumerate(self.available(src, dst, Plugin)): + for plugin, inst in self.available(src, dst, Plugin): inst.point = point_inst inst.name = getattr(plugin, 'name', None) - inst.index = _i + inst.id = getattr(plugin, 'id') if hasattr(plugin, 'title'): inst.title = six.text_type(getattr(plugin, 'title')) inst.save() diff --git a/djangoplugins/migrations/0002_add_id_to_plugins_uniq.py b/djangoplugins/migrations/0002_add_id_to_plugins_uniq.py index 0faebcc..2bdd5ee 100644 --- a/djangoplugins/migrations/0002_add_id_to_plugins_uniq.py +++ b/djangoplugins/migrations/0002_add_id_to_plugins_uniq.py @@ -14,6 +14,6 @@ class Migration(migrations.Migration): operations = [ migrations.AlterUniqueTogether( name='plugin', - unique_together=set([('point', 'name', 'index')]), + unique_together=set([('point', 'name', 'id')]), ), ]