diff --git a/bookwyrm/models/activitypub_mixin.py b/bookwyrm/models/activitypub_mixin.py index 3139e2de8..d1ca3747a 100644 --- a/bookwyrm/models/activitypub_mixin.py +++ b/bookwyrm/models/activitypub_mixin.py @@ -126,18 +126,6 @@ class ActivitypubMixin: # there OUGHT to be only one match return match.first() - def get_dedpulication_field_json(self): - """A json blob of deduplication fields (like remote_id, or ISBN)""" - data = {} - for field in self._meta.get_fields(): - if ( - not hasattr(field, "deduplication_field") - or not field.deduplication_field - ): - continue - data[field.name] = getattr(self, field.name) - return data - def broadcast(self, activity, sender, software=None, queue=BROADCAST): """send out an activity""" broadcast_task.apply_async( diff --git a/bookwyrm/models/book.py b/bookwyrm/models/book.py index 6c40061b9..6a779b0f6 100644 --- a/bookwyrm/models/book.py +++ b/bookwyrm/models/book.py @@ -2,7 +2,6 @@ from itertools import chain import re -from django.apps import apps from django.contrib.postgres.search import SearchVectorField from django.contrib.postgres.indexes import GinIndex from django.core.cache import cache @@ -381,22 +380,16 @@ class Edition(Book): return super().save(*args, **kwargs) + @transaction.atomic def repair(self): """If an edition is in a bad state (missing a work), let's fix that""" # made sure it actually NEEDS reapir if self.parent_work: return - # try to find a duplicate of this edition first - model = apps.get_model("bookwyrm.Edition", require_ready=True) - data = self.get_dedpulication_field_json() - existing_match = model.find_existing(data) - # assign this edition to the parent of the duplicate edition - if existing_match and existing_match.parent_work: - new_work = existing_match.parent_work - else: - new_work = Work.objects.create(title=self.title) + new_work = Work.objects.create(title=self.title) + new_work.authors.set(self.authors.all()) self.parent_work = new_work self.save(update_fields=["parent_work"], broadcast=False) diff --git a/bookwyrm/tests/models/test_book_model.py b/bookwyrm/tests/models/test_book_model.py index a615a76af..6dd83b764 100644 --- a/bookwyrm/tests/models/test_book_model.py +++ b/bookwyrm/tests/models/test_book_model.py @@ -24,8 +24,7 @@ class Book(TestCase): title="Example Work", remote_id="https://example.com/book/1" ) self.first_edition = models.Edition.objects.create( - title="Example Edition", - parent_work=self.work, + title="Example Edition", parent_work=self.work, isbn_10="1111111111" ) self.second_edition = models.Edition.objects.create( title="Another Example Edition", @@ -147,9 +146,11 @@ class Book(TestCase): def test_repair_edition(self): """Fix editions with no works""" edition = models.Edition.objects.create(title="test") + edition.authors.set([models.Author.objects.create(name="Author Name")]) self.assertIsNone(edition.parent_work) edition.repair() edition.refresh_from_db() self.assertEqual(edition.parent_work.title, "test") + self.assertEqual(edition.parent_work.authors.count(), 1)