Skip to content

Commit

Permalink
Merge pull request #1616 from laws-africa/commencements-bug-fix
Browse files Browse the repository at this point in the history
Guard against objects without `commencements_json` attribute
  • Loading branch information
nickmwangemi authored Nov 8, 2023
2 parents 0cbc91a + 14892a8 commit 58fdd44
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions peachjam/adapters/adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,22 +395,23 @@ def fetch_relationships(self, imported_document, created_document):
object_work=amending_work,
)

commencements = created_document.commencements_json
if commencements:
for commencement in commencements:
if (
commencement["commencing_frbr_uri"]
and commencement["commencing_title"]
):
commencing_work, _ = Work.objects.get_or_create(
frbr_uri=commencement["commencing_frbr_uri"],
defaults={"title": commencement["commencing_title"]},
)
self.create_relationship(
"commenced-by",
subject_work=subject_work,
object_work=commencing_work,
)
if hasattr(created_document, "commencements_json"):
commencements = created_document.commencements_json
if commencements:
for commencement in commencements:
if (
commencement["commencing_frbr_uri"]
and commencement["commencing_title"]
):
commencing_work, _ = Work.objects.get_or_create(
frbr_uri=commencement["commencing_frbr_uri"],
defaults={"title": commencement["commencing_title"]},
)
self.create_relationship(
"commenced-by",
subject_work=subject_work,
object_work=commencing_work,
)
logger.info(f"Fetching of relationships for {subject_work} is complete!")

def create_relationship(self, slug, subject_work, object_work):
Expand Down

0 comments on commit 58fdd44

Please sign in to comment.