Merge pull request #27434 from edx/jhynes/microba-1139_cert-error-cleanup

fix: Clean up old errors from certificate records now in `downloadable` status
This commit is contained in:
Justin Hynes
2021-04-28 07:37:16 -04:00
committed by GitHub
2 changed files with 36 additions and 6 deletions

View File

@@ -0,0 +1,30 @@
# Generated by Django 2.2.20 on 2021-04-27 18:12
from django.db import migrations
class Migration(migrations.Migration):
"""
Clean records in the `CERTIFICATES_GENERATEDCERTIFICATE` table that are in the downloadable state but also have
old errors still part of their certificate record.
As part of this migration we are also altering the Managers for the GeneratedCertificate model. We need the ability
to access the `objects` attribute for the cleanup.
"""
def cleanup_certificate_records(apps, schema_editor):
GeneratedCertificate = apps.get_model('certificates', 'GeneratedCertificate')
GeneratedCertificate.objects.filter(status='downloadable').exclude(error_reason='').update(error_reason='')
dependencies = [
('certificates', '0024_delete_allowlistgenerationconfiguration'),
]
operations = [
migrations.AlterModelManagers(
name='generatedcertificate',
managers=[
],
),
migrations.RunPython(cleanup_certificate_records, reverse_code=migrations.RunPython.noop)
]

View File

@@ -202,7 +202,7 @@ class EligibleAvailableCertificateManager(EligibleCertificateManager):
A manager for `GeneratedCertificate` models that automatically
filters out ineligible certs and any linked to nonexistent courses.
Adds to the super class filtering ot also exclude certificates for
Adds to the super class filtering to also exclude certificates for
courses that do not have a corresponding CourseOverview.
"""
@@ -233,6 +233,11 @@ class GeneratedCertificate(models.Model):
# the course_modes app is loaded, resulting in a Django deprecation warning.
from common.djangoapps.course_modes.models import CourseMode # pylint: disable=reimported
# Normal object manager, which should only be used when ineligible
# certificates (i.e. new audit certs) should be included in the
# results. Django requires us to explicitly declare this.
objects = models.Manager()
# Only returns eligible certificates. This should be used in
# preference to the default `objects` manager in most cases.
eligible_certificates = EligibleCertificateManager()
@@ -241,11 +246,6 @@ class GeneratedCertificate(models.Model):
# associated CourseOverview
eligible_available_certificates = EligibleAvailableCertificateManager()
# Normal object manager, which should only be used when ineligible
# certificates (i.e. new audit certs) should be included in the
# results. Django requires us to explicitly declare this.
objects = models.Manager()
MODES = Choices(
'verified',
'honor',