From e558d71b1024e0018ecaf6fdfd75afce18601d74 Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Wed, 28 Aug 2024 03:01:19 -0700 Subject: [PATCH] fix uuid checks on save --- archivebox/abid_utils/models.py | 9 ++++++++ archivebox/builtin_plugins/singlefile/apps.py | 3 ++- archivebox/core/models.py | 21 ------------------- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/archivebox/abid_utils/models.py b/archivebox/abid_utils/models.py index e5502cea..c62f7208 100644 --- a/archivebox/abid_utils/models.py +++ b/archivebox/abid_utils/models.py @@ -93,6 +93,7 @@ class ABIDModel(models.Model): super().save(*args, **kwargs) assert str(self.id) == str(self.ABID.uuid), f'self.id {self.id} does not match self.ABID {self.ABID.uuid}' assert str(self.abid) == str(self.ABID), f'self.abid {self.id} does not match self.ABID {self.ABID.uuid}' + assert str(self.uuid) == str(self.ABID.uuid), f'self.uuid ({self.uuid}) does not match .ABID.uuid ({self.ABID.uuid})' @property def abid_values(self) -> Dict[str, Any]: @@ -186,6 +187,14 @@ class ABIDModel(models.Model): Get a uuid.UUID (v4) representation of the object's ABID. """ return self.ABID.uuid + + @property + def uuid(self) -> str: + """ + Get a str uuid.UUID (v4) representation of the object's ABID. + """ + assert str(self.id) == str(self.ABID.uuid) + return str(self.id) @property def TypeID(self) -> TypeID: diff --git a/archivebox/builtin_plugins/singlefile/apps.py b/archivebox/builtin_plugins/singlefile/apps.py index 090c7226..782bd5d0 100644 --- a/archivebox/builtin_plugins/singlefile/apps.py +++ b/archivebox/builtin_plugins/singlefile/apps.py @@ -91,4 +91,5 @@ class SinglefileConfig(AppConfig): verbose_name = 'SingleFile' def ready(self): - print('Loaded singlefile plugin') + pass + # print('Loaded singlefile plugin') diff --git a/archivebox/core/models.py b/archivebox/core/models.py index bed9e65a..bf2c1fec 100644 --- a/archivebox/core/models.py +++ b/archivebox/core/models.py @@ -158,9 +158,6 @@ class Snapshot(ABIDModel): objects = SnapshotManager() - @property - def uuid(self): - return self.id def __repr__(self) -> str: title = (self.title_stripped or '-')[:64] @@ -170,13 +167,6 @@ class Snapshot(ABIDModel): title = (self.title_stripped or '-')[:64] return f'[{self.timestamp}] {self.url[:64]} ({title})' - def save(self, *args, **kwargs): - super().save(*args, **kwargs) - try: - assert str(self.id) == str(self.ABID.uuid) == str(self.uuid), f'Snapshot.id ({self.id}) does not match .ABID.uuid ({self.ABID.uuid})' - except AssertionError as e: - print(e) - @classmethod def from_json(cls, info: dict): info = {k: v for k, v in info.items() if k in cls.keys} @@ -471,17 +461,6 @@ class ArchiveResult(ABIDModel): def __str__(self): return self.extractor - def save(self, *args, **kwargs): - super().save(*args, **kwargs) - try: - assert str(self.id) == str(self.ABID.uuid) == str(self.uuid), f'ArchiveResult.id ({self.id}) does not match .ABID.uuid ({self.ABID.uuid})' - except AssertionError as e: - print(e) - - @property - def uuid(self): - return self.id - @cached_property def snapshot_dir(self): return Path(self.snapshot.link_dir)