From 02350e0feeaaf60133008bb621d003a9d50c835b Mon Sep 17 00:00:00 2001 From: aarif Date: Fri, 27 Dec 2019 19:08:39 +0500 Subject: [PATCH] added on_delete parameter to foreign_key and oneToOne fields changes made to fix issues with quality --- .../migrations/0013_persistentsubsectiongradeoverride.py | 3 ++- lms/djangoapps/grades/models.py | 4 ++-- lms/djangoapps/program_enrollments/models.py | 2 +- openedx/core/djangoapps/oauth_dispatch/models.py | 8 +++++--- openedx/core/djangoapps/user_api/models.py | 2 +- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lms/djangoapps/grades/migrations/0013_persistentsubsectiongradeoverride.py b/lms/djangoapps/grades/migrations/0013_persistentsubsectiongradeoverride.py index 23079ea0fc..ead8ddad71 100644 --- a/lms/djangoapps/grades/migrations/0013_persistentsubsectiongradeoverride.py +++ b/lms/djangoapps/grades/migrations/0013_persistentsubsectiongradeoverride.py @@ -21,7 +21,8 @@ class Migration(migrations.Migration): ('possible_all_override', models.FloatField(null=True, blank=True)), ('earned_graded_override', models.FloatField(null=True, blank=True)), ('possible_graded_override', models.FloatField(null=True, blank=True)), - ('grade', models.OneToOneField(related_name='override', to='grades.PersistentSubsectionGrade')), + ('grade', models.OneToOneField(related_name='override', to='grades.PersistentSubsectionGrade', + on_delete=models.CASCADE)), ], ), ] diff --git a/lms/djangoapps/grades/models.py b/lms/djangoapps/grades/models.py index b38d19f99e..65ced6f9ac 100644 --- a/lms/djangoapps/grades/models.py +++ b/lms/djangoapps/grades/models.py @@ -655,7 +655,7 @@ class PersistentSubsectionGradeOverride(models.Model): class Meta(object): app_label = "grades" - grade = models.OneToOneField(PersistentSubsectionGrade, related_name='override') + grade = models.OneToOneField(PersistentSubsectionGrade, related_name='override', on_delete=models.CASCADE) # Created/modified timestamps prevent race-conditions when using with async rescoring tasks created = models.DateTimeField(auto_now_add=True, db_index=True) @@ -806,7 +806,7 @@ class PersistentSubsectionGradeOverrideHistory(models.Model): choices=OVERRIDE_ACTIONS, default=CREATE_OR_UPDATE ) - user = models.ForeignKey(User, blank=True, null=True) + user = models.ForeignKey(User, blank=True, null=True, on_delete=models.CASCADE) comments = models.CharField(max_length=300, blank=True, null=True) created = models.DateTimeField(auto_now_add=True, db_index=True) diff --git a/lms/djangoapps/program_enrollments/models.py b/lms/djangoapps/program_enrollments/models.py index 06ff34f2a5..c6ca16a853 100644 --- a/lms/djangoapps/program_enrollments/models.py +++ b/lms/djangoapps/program_enrollments/models.py @@ -40,7 +40,7 @@ class ProgramEnrollment(TimeStampedModel): # pylint: disable=model-missing-unic user = models.ForeignKey( User, null=True, - blank=True + blank=True, on_delete=models.CASCADE ) external_user_key = models.CharField( db_index=True, diff --git a/openedx/core/djangoapps/oauth_dispatch/models.py b/openedx/core/djangoapps/oauth_dispatch/models.py index dd24bed7d6..dfa24631a0 100644 --- a/openedx/core/djangoapps/oauth_dispatch/models.py +++ b/openedx/core/djangoapps/oauth_dispatch/models.py @@ -69,7 +69,8 @@ class ApplicationAccess(models.Model): .. no_pii: """ - application = models.OneToOneField(oauth2_settings.APPLICATION_MODEL, related_name='access') + application = models.OneToOneField(oauth2_settings.APPLICATION_MODEL, related_name='access', + on_delete=models.CASCADE) scopes = ListCharField( base_field=models.CharField(max_length=32), size=25, @@ -109,8 +110,9 @@ class ApplicationOrganization(models.Model): (RELATION_TYPE_CONTENT_ORG, _('Content Provider')), ) - application = models.ForeignKey(oauth2_settings.APPLICATION_MODEL, related_name='organizations') - organization = models.ForeignKey(Organization) + application = models.ForeignKey(oauth2_settings.APPLICATION_MODEL, related_name='organizations', + on_delete=models.CASCADE) + organization = models.ForeignKey(Organization, on_delete=models.CASCADE) relation_type = models.CharField( max_length=32, choices=RELATION_TYPES, diff --git a/openedx/core/djangoapps/user_api/models.py b/openedx/core/djangoapps/user_api/models.py index 8deec93f68..3c54a33a26 100644 --- a/openedx/core/djangoapps/user_api/models.py +++ b/openedx/core/djangoapps/user_api/models.py @@ -204,7 +204,7 @@ class UserRetirementPartnerReportingStatus(TimeStampedModel): .. pii_types: name, username, email_address .. pii_retirement: local_api """ - user = models.OneToOneField(User) + user = models.OneToOneField(User, on_delete=models.CASCADE) original_username = models.CharField(max_length=150, db_index=True) original_email = models.EmailField(db_index=True) original_name = models.CharField(max_length=255, blank=True, db_index=True)