Skip to content

Commit

Permalink
Handle contribution import exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
hancush committed Jul 16, 2024
1 parent 791a7dd commit 8e6d5f0
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions camp_fin/management/commands/import_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,15 @@ def _get_filing(self, record):
try:
pac = models.PAC.objects.get(entity__user_id=state_id)
except models.PAC.DoesNotExist:
pac = models.PAC.objects.get(name=record["Committee Name"])
pac.entity.user_id = state_id
pac.entity.save()
try:
pac = models.PAC.objects.get(name=record["Committee Name"])
except models.PAC.DoesNotExist:
msg = f"PAC with name {record['Committee Name']} does not exist."
self.stderr.write(msg)
raise ValueError(msg)
else:
pac.entity.user_id = state_id
pac.entity.save()

try:
# candidate entity
Expand Down Expand Up @@ -252,6 +258,10 @@ def _get_filing(self, record):
filing = filings.get()
except models.Filing.DoesNotExist:
raise ValueError
except models.Filing.MultipleObjectsExist:
msg = f"{filings.count()} filings found for PAC {pac} from record {record}: {filings}"
self.stderr.write(msg)
raise ValueError(msg)

return filing

Expand Down

0 comments on commit 8e6d5f0

Please sign in to comment.