diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 8256e044c4..4d7538af39 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -15,6 +15,10 @@ Change Log Unreleased ---------- +[4.13.14] +--------- +* feat: handle Degreed 409 case (mark as active instead of recreating course) + [4.13.13] --------- * fix: adding additional info to the enterprise group serializer diff --git a/enterprise/__init__.py b/enterprise/__init__.py index 4535e3e13e..6b75a7c670 100644 --- a/enterprise/__init__.py +++ b/enterprise/__init__.py @@ -2,4 +2,4 @@ Your project description goes here. """ -__version__ = "4.13.13" +__version__ = "4.13.14" diff --git a/integrated_channels/degreed2/client.py b/integrated_channels/degreed2/client.py index 7929f12de9..b495f5e447 100644 --- a/integrated_channels/degreed2/client.py +++ b/integrated_channels/degreed2/client.py @@ -280,15 +280,24 @@ def create_content_metadata(self, serialized_data): external_id = a_course.get('external-id') status_code, response_body = self._sync_content_metadata(a_course, 'post', self.get_courses_url()) if status_code == 409: - # course already exists, don't raise failure, but log and move on + # course already exists, don't raise failure, but try to mark it as active on Degreed side + # if succeeds, we'll treat this as a success LOGGER.warning( self.make_log_msg( external_id, - f'Course with integration_id = {external_id} already exists, ' + f'Course with integration_id = {external_id} already exists, marking it as active' ) ) - # content already exists, we'll treat this as a success - status_code = 200 + try: + channel_metadata_item['courses'][0]['obsolete'] = False + return self.update_content_metadata(json.dumps(channel_metadata_item).encode('utf-8')) + except requests.exceptions.RequestException as exc: + raise ClientError( + 'Degreed2APIClient request failed while handling 409: {error} {message}'.format( + error=exc.__class__.__name__, + message=str(exc) + ) + ) from exc elif status_code >= 400: raise ClientError( f'Degreed2APIClient create_content_metadata failed with status {status_code}: {response_body}', diff --git a/tests/test_integrated_channels/test_degreed2/test_client.py b/tests/test_integrated_channels/test_degreed2/test_client.py index bbc3c409f2..163175804e 100644 --- a/tests/test_integrated_channels/test_degreed2/test_client.py +++ b/tests/test_integrated_channels/test_degreed2/test_client.py @@ -440,6 +440,12 @@ def test_create_content_metadata_course_exists(self): json='{}', status=200 ) + responses.add( + responses.PATCH, + f'{enterprise_config.degreed_base_url}api/v2/content/courses/{degreed_course_id}', + json='{}', + status=200 + ) status_code, _ = degreed_api_client.create_content_metadata(create_course_payload()) # we treat as "course exists" as a success assert status_code == 200