From 3acb0aecec7067b71b3f6ca2f70ee809f4d47fef Mon Sep 17 00:00:00 2001 From: Steven Loria Date: Tue, 5 Dec 2017 19:52:08 -0500 Subject: [PATCH] Prevent updating auto_now fields in preprint migration --- osf/migrations/0069_auto_20171127_1119.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/osf/migrations/0069_auto_20171127_1119.py b/osf/migrations/0069_auto_20171127_1119.py index 670df08f746..002aec80d25 100644 --- a/osf/migrations/0069_auto_20171127_1119.py +++ b/osf/migrations/0069_auto_20171127_1119.py @@ -5,6 +5,8 @@ from django.db import migrations from osf.models import PreprintService +from osf.utils.migrations import disable_auto_now_fields + logger = logging.getLogger(__name__) def add_preprint_doi_created(apps, schema_editor): @@ -16,14 +18,15 @@ def add_preprint_doi_created(apps, schema_editor): current_preprint = 0 logger.info('{} published preprints found with preprint_doi_created is null.'.format(preprints_count)) - for preprint in null_preprint_doi_created: - current_preprint += 1 - if preprint.get_identifier('doi'): - preprint.preprint_doi_created = preprint.date_published - preprint.save() - logger.info('Preprint ID {}, {}/{} preprint_doi_created field populated.'.format(preprint._id, current_preprint, preprints_count)) - else: - logger.info('Preprint ID {}, {}/{} skipped because a DOI has not been created.'.format(preprint._id, current_preprint, preprints_count)) + with disable_auto_now_fields(PreprintService): + for preprint in null_preprint_doi_created: + current_preprint += 1 + if preprint.get_identifier('doi'): + preprint.preprint_doi_created = preprint.date_published + preprint.save() + logger.info('Preprint ID {}, {}/{} preprint_doi_created field populated.'.format(preprint._id, current_preprint, preprints_count)) + else: + logger.info('Preprint ID {}, {}/{} skipped because a DOI has not been created.'.format(preprint._id, current_preprint, preprints_count)) def reverse_func(apps, schema_editor): """