Skip to content

Commit 434d7a2

Browse files
hotfix
1 parent b437baf commit 434d7a2

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

backend/metering_billing/migrations/0180_transfer_data.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@ def copy_events_to_idempotencecheck(apps, schema_editor):
1010
for event in Event.objects.order_by(
1111
"idempotency_id", "organization", "-time_created"
1212
).values("time_created", "idempotency_id", "organization"):
13-
idempotency_check, created = IdempotenceCheck.objects.get_or_create(
14-
idempotency_id=event["idempotency_id"],
15-
organization_id=event["organization"],
16-
)
17-
if created or not idempotency_check.time_created:
18-
idempotency_check.time_created = event["time_created"]
19-
idempotency_check.save()
13+
try:
14+
IdempotenceCheck.objects.get(
15+
idempotency_id=event["idempotency_id"],
16+
organization_id=event["organization"],
17+
)
18+
except IdempotenceCheck.DoesNotExist:
19+
IdempotenceCheck.objects.create(
20+
time_created=event["time_created"],
21+
idempotency_id=event["idempotency_id"],
22+
organization_id=event["organization"],
23+
)
2024

2125

2226
class Migration(migrations.Migration):

0 commit comments

Comments
 (0)