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

feat: normalize start/end/enroll_by dates across content types #666

Merged
merged 1 commit into from
Aug 30, 2023

Conversation

pwnage101
Copy link
Contributor

@pwnage101 pwnage101 commented Aug 18, 2023

ENT-7545

Ticket Link

[enterprise-catalog] Expose net-new fields on the existing content-metadata API

Post-review

  • Squash commits into discrete sets of changes
  • Ensure that once the changes have been deployed to stage, prod is manually deployed

@pwnage101 pwnage101 force-pushed the pwnage101/ENT-7545 branch 5 times, most recently from 55d2016 to a0b163e Compare August 22, 2023 21:52
@pwnage101 pwnage101 marked this pull request as ready for review August 22, 2023 21:55
Comment on lines +375 to +377
# Exec ed provides the start/end dates in additional_metadata, so we should copy those over to the keys that
# we use (inside the advertised course run).
Copy link
Contributor Author

@pwnage101 pwnage101 Aug 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note about this if-block: Prior to this PR, it ran BEFORE merging the full metadata from /api/v1/courses/ into the local metadata object, but now it runs AFTER merging full metadata. The additional_metadata key is not present in the /api/v1/search/all/ response, only in /api/v1/courses/, so the only way this code worked was by running the task twice on a given course.

Old behavior:

  1. Load basic metadata from /api/v1/search/all/.
  2. Attempt to copy start/end from additional_metdata (fails because additional_metdata doesn't exist yet).
  3. Merge full metadata from /api/v1/courses/ (adds additional_metdata).
  4. Load basic metadata from /api/v1/search/all/.
  5. Attempt to copy start/end from additional_metdata (success).

New behavior:

  1. Load basic metadata from /api/v1/search/all/.
  2. Merge full metadata from /api/v1/courses/ (adds additional_metdata).
  3. Attempt to copy start/end from additional_metdata (success).

Comment on lines -309 to -314
course_run = _get_course_run_by_uuid(json_meta, course_run_uuid)
if course_run is not None:
course_run_meta = metadata_by_key.get(course_run.get('key'))
if hasattr(course_run_meta, 'json_metadata'):
course_run_meta.json_metadata.update({'start': start_date, 'end': end_date})
modified_content_metadata_records.append(course_run_meta)
Copy link
Contributor Author

@pwnage101 pwnage101 Aug 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section is being removed because it is a no-op. Course runs are never processed in this task.

https://github.com/openedx/enterprise-catalog/blob/d868759/enterprise_catalog/apps/api/tasks.py#L250-L251

Comment on lines -405 to -410
# add aggregation_key and uuid to course objects since they should now exist
# after merging the original json_metadata with the course metadata
course_data_1.update(metadata_1.json_metadata)
course_data_2.update(metadata_2.json_metadata)
course_data_1.update({'aggregation_key': 'course:fakeX'})
course_data_2.update({'aggregation_key': 'course:testX'})
Copy link
Contributor Author

@pwnage101 pwnage101 Aug 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more of the testing pattern we're trying to move away from. It's like doing "x = y; assert y = x". Instead we should test each expected key manually.

Copy link
Contributor

@iloveagent57 iloveagent57 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple nits/suggestions.

enterprise_catalog/apps/api/tasks.py Show resolved Hide resolved
enterprise_catalog/apps/api/tasks.py Outdated Show resolved Hide resolved
enterprise_catalog/apps/api/tasks.py Outdated Show resolved Hide resolved
enterprise_catalog/apps/api/tasks.py Outdated Show resolved Hide resolved
enterprise_catalog/apps/api/tests/test_tasks.py Outdated Show resolved Hide resolved
@pwnage101 pwnage101 force-pushed the pwnage101/ENT-7545 branch 6 times, most recently from 6f081f6 to f8a0f2d Compare August 23, 2023 20:53
},
)
@ddt.unpack
def test_find_best_mode_seat(self, seats, expected_seat):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: added this test since last review.

enterprise_catalog/apps/api/tasks.py Outdated Show resolved Hide resolved
enterprise_catalog/apps/api/tasks.py Outdated Show resolved Hide resolved
enterprise_catalog/apps/api/constants.py Outdated Show resolved Hide resolved
@pwnage101 pwnage101 force-pushed the pwnage101/ENT-7545 branch 2 times, most recently from 09026ec to 3a5bf68 Compare August 25, 2023 21:18
Comment on lines -516 to -519
'additional_metadata': {
'start_date': '2023-03-01T00:00:00Z',
'end_date': '2023-04-09T23:59:59Z',
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove additional_metadata from the starter course metadata to properly simulate an object freshly seeded by /api/v1/search/all/ via a different task.

Copy link
Member

@adamstankiewicz adamstankiewicz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

"""


class CourseMode():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit/inform]: Similar course mode constants are also defined under enterprise_catalog/apps/catalog/constants.py (e.g., CONTENT_COURSE_TYPE_ALLOW_LIST). We could likely consolidate to ensure that those hardcoded course modes also rely on this new CourseMode class.

That said, we might want to define this constant under the constants.py file under the catalog app, so they can be more readily shared across both the api and catalog apps.

I wouldn't say this is blocking feedback on this PR; likely something I can tackle in ENT-7548, which relates to ensuring these normalized dates get into Algolia so they're available across all course types.

@iloveagent57 iloveagent57 merged commit a5d2d06 into master Aug 30, 2023
5 checks passed
@iloveagent57 iloveagent57 deleted the pwnage101/ENT-7545 branch August 30, 2023 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants