Skip to content

Commit

Permalink
fix(management): ensure Differentia is created if not found
Browse files Browse the repository at this point in the history
- in populate_diff_id_fields.py
- removed obsolete else block
  • Loading branch information
lucasmarchd01 committed Aug 6, 2024
1 parent e7b98cc commit 390cb57
Showing 1 changed file with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,22 @@ def handle(self, *args, **kwargs):
Q(differentiae_database__isnull=False) & Q(diff_db__isnull=True)
).count()
count = 0
chant: Chant

for chant in chants:
try:
differentia_id: Optional[str] = chant.differentiae_database
differentia = Differentia.objects.get(differentia_id=differentia_id)
if differentia:
chant.diff_db = differentia
else:
# If the Differentia doesn't exist, create a new one
differentia = Differentia(
differentia_id=differentia_id,
)
differentia.save()
chant.diff_db = differentia
chant.save()
except Differentia.DoesNotExist:
# If the Differentia doesn't exist, create a new one
differentia = Differentia(differentia_id=differentia_id)
differentia.save()
self.stdout.write(
self.style.WARNING(f"Differentia not found for chant: {chant}")
self.style.WARNING(f"Differentia created for chant: {chant}")
)

chant.diff_db = differentia
chant.save()

count += 1
if count % 100 == 0:
self.stdout.write(
Expand Down

0 comments on commit 390cb57

Please sign in to comment.