Skip to content

Commit

Permalink
fix TransactionManagementError bug
Browse files Browse the repository at this point in the history
  • Loading branch information
amyasnikov committed Dec 3, 2023
1 parent 67e36bb commit a0c80d4
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions validity/migrations/0004_netbox35_scripts.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pathlib import Path
import sys

from django.db import IntegrityError, migrations
from django.db import IntegrityError, migrations, transaction
from django.utils.translation import gettext_lazy as _
from validity import scripts
from validity import config
Expand Down Expand Up @@ -29,9 +29,10 @@ def forward_func(apps, schema_editor):
module = ScriptModule(data_source=data_source, data_file=data_file, file_root="scripts", auto_sync_enabled=True)
module.clean()
try:
module.save()
with transaction.atomic():
module.save()
except IntegrityError:
print(f"{module.full_path} already exists, ignoring", file=sys.stderr) # noqa
print(f"\n{module.full_path} already exists, ignoring", file=sys.stderr) # noqa


def reverse_func(apps, schema_editor):
Expand Down

0 comments on commit a0c80d4

Please sign in to comment.