Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

working draft on possible code fixes to partially applied migration #1991

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,21 @@ class Migration(migrations.Migration):
('blackboard', '0017_alter_historicalblackboardenterprisecustomerconfiguration_options'),
]

# johnnagro 20240118 DOS-4490
# Making this migration a no-op to revert a partially applied deploy migration
# operations = [
# migrations.AddField(
# model_name='blackboardlearnerassessmentdatatransmissionaudit',
# name='transmission_status',
# field=models.JSONField(blank=True, default=list, null=True),
# ),
# migrations.AddField(
# model_name='blackboardlearnerdatatransmissionaudit',
# name='transmission_status',
# field=models.JSONField(blank=True, default=list, null=True),
# ),
# ]

operations = [
migrations.AddField(
model_name='blackboardlearnerassessmentdatatransmissionaudit',
name='transmission_status',
field=models.JSONField(blank=True, default=list, null=True),
),
migrations.AddField(
model_name='blackboardlearnerdatatransmissionaudit',
name='transmission_status',
field=models.JSONField(blank=True, default=list, null=True),
),
migrations.RunPython(migrations.RunPython.noop, reverse_code=migrations.RunPython.noop)
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by Django 3.2.22 on 2024-01-18 18:22

from django.db import migrations
from django.core.exceptions import FieldDoesNotExist
from integrated_channels.blackboard.models import *


def forwards_func(apps, schema_editor):
try:
if field := BlackboardLearnerDataTransmissionAudit._meta.get_field('transmission_status'):
schema_editor.remove_field(BlackboardLearnerDataTransmissionAudit, field)
except FieldDoesNotExist:
pass

try:
if field := BlackboardLearnerAssessmentDataTransmissionAudit._meta.get_field('transmission_status'):
schema_editor.remove_field(BlackboardLearnerAssessmentDataTransmissionAudit, field)
except FieldDoesNotExist:
pass


class Migration(migrations.Migration):

dependencies = [
('blackboard', '0018_auto_20240110_1301'),
]

# johnnagro 20240118 DOS-4490
# we are reverting a partially applied deployment migration
# this migration conditionally cleans up the previous migration operations
# only if they were part of the partially applied ones

operations = [
migrations.RunPython(forwards_func, reverse_code=migrations.RunPython.noop)
]
21 changes: 21 additions & 0 deletions integrated_channels/canvas/migrations/0034_auto_20240118_1822.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 3.2.22 on 2024-01-18 18:22

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('canvas', '0033_auto_20240110_1301'),
]

operations = [
migrations.RemoveField(
model_name='canvaslearnerassessmentdatatransmissionaudit',
name='transmission_status',
),
migrations.RemoveField(
model_name='canvaslearnerdatatransmissionaudit',
name='transmission_status',
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 3.2.22 on 2024-01-18 18:22

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('cornerstone', '0032_cornerstonelearnerdatatransmissionaudit_transmission_status'),
]

operations = [
migrations.RemoveField(
model_name='cornerstonelearnerdatatransmissionaudit',
name='transmission_status',
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 3.2.22 on 2024-01-18 18:22

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('degreed', '0032_degreedlearnerdatatransmissionaudit_transmission_status'),
]

operations = [
migrations.RemoveField(
model_name='degreedlearnerdatatransmissionaudit',
name='transmission_status',
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 3.2.22 on 2024-01-18 18:22

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('degreed2', '0024_degreed2learnerdatatransmissionaudit_transmission_status'),
]

operations = [
migrations.RemoveField(
model_name='degreed2learnerdatatransmissionaudit',
name='transmission_status',
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 3.2.22 on 2024-01-18 18:22

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('integrated_channel', '0031_genericlearnerdatatransmissionaudit_transmission_status'),
]

operations = [
migrations.RemoveField(
model_name='genericlearnerdatatransmissionaudit',
name='transmission_status',
),
]
14 changes: 0 additions & 14 deletions integrated_channels/integrated_channel/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,20 +607,6 @@ def _payload_data(self):
'grade': self.grade,
}

def add_transmission_status(self, status_code, error_message):
"""
Append the new entry to the list, keeping the list limited to latest three entries.
"""
new_entry = {
'timestamp': timezone.now().isoformat(),
'Status_code': status_code,
'error_message': error_message,
}

self.transmission_status.append(new_entry)

self.transmission_status = self.transmission_status[-TRANSMISSION_STATUS_RECORDS_LIMIT:]


class GenericLearnerDataTransmissionAudit(LearnerDataTransmissionAudit):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@ def transmit(self, payload, **kwargs): # pylint: disable=arguments-differ
was_successful = code < 300
learner_data.status = str(code)
learner_data.error_message = body if not was_successful else ''
learner_data.add_transmission_status(learner_data.status, learner_data.error_message)
learner_data.save()
self.enterprise_configuration.update_learner_synced_at(action_happened_at, was_successful)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 3.2.22 on 2024-01-18 18:22

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('moodle', '0032_auto_20240117_1202'),
]

operations = [
migrations.RemoveField(
model_name='moodlelearnerdatatransmissionaudit',
name='transmission_status',
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 3.2.22 on 2024-01-18 18:22

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('sap_success_factors', '0015_sapsuccessfactorslearnerdatatransmissionaudit_transmission_status'),
]

operations = [
migrations.RemoveField(
model_name='sapsuccessfactorslearnerdatatransmissionaudit',
name='transmission_status',
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 3.2.22 on 2024-01-18 18:22

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('xapi', '0012_xapilearnerdatatransmissionaudit_transmission_status'),
]

operations = [
migrations.RemoveField(
model_name='xapilearnerdatatransmissionaudit',
name='transmission_status',
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -222,23 +222,3 @@ def test_learner_data_transmission_dry_run_mode(self, already_transmitted_mock,
)
# with dry_run_mode_enabled = True we shouldn't be able to call this method
assert not self.learner_transmitter.client.create_assessment_reporting.called

def test_transmission_status_learner_data_transmission(self):
"""
Test that transmission status records three most recent status instances.
"""
self.create_course_completion_mock.return_value = 200, ''

transmitter = learner_data.SapSuccessFactorsLearnerTransmitter(self.enterprise_config)
for _ in range(TRANSMISSION_STATUS_RECORDS_LIMIT + 1):
if _ == TRANSMISSION_STATUS_RECORDS_LIMIT:
self.create_course_completion_mock.return_value = 400, '{"error":{"code":null,"message":"Invalid value for property \'courseCompleted\'."}}'
transmitter.transmit(self.exporter([self.payload]))
actual_transmission_status = self.payload.transmission_status

expected_transmission_status = [
{'timestamp': mock.ANY, 'Status_code': '200', 'error_message': ''},
{'timestamp': mock.ANY, 'Status_code': '200', 'error_message': ''},
{'timestamp': mock.ANY, 'Status_code': '400', 'error_message': 'Client create_course_completion failed: {"error":{"code":null,"message":"Invalid value for property \'courseCompleted\'."}}'},
]
assert expected_transmission_status == actual_transmission_status
Loading