Skip to content

Commit

Permalink
Update script to fix year bug (#4142)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimasciput authored Aug 12, 2024
1 parent 93e34d5 commit 81e31b2
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions scripts/management/commands/fix_collection_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
from django.db.models import F
from django.db import transaction, connection

from bims.signals.utils import disconnect_bims_signals, connect_bims_signals

logger = logging.getLogger(__name__)

BATCH_SIZE = 1000
BATCH_SIZE = 100


class Command(BaseCommand):
Expand All @@ -25,7 +27,9 @@ def handle(self, *args, **options):
schema_name = options.get('schema_name', '')
if schema_name:
connection.set_schema(schema_name)
disconnect_bims_signals()
self.fix_collection_dates()
connect_bims_signals()

def fix_collection_dates(self):
mismatched_records = BiologicalCollectionRecord.objects.exclude(
Expand All @@ -38,10 +42,11 @@ def fix_collection_dates(self):
if record_count == 0:
return

with transaction.atomic():
for start in range(0, record_count, BATCH_SIZE):
for start in range(0, record_count, BATCH_SIZE):
with transaction.atomic():
batch = mismatched_records[start:start + BATCH_SIZE]
self.process_batch(batch)
print('next batch')

def process_batch(self, batch):
for record in batch.iterator():
Expand Down

0 comments on commit 81e31b2

Please sign in to comment.