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

fix: video page api error #34883

Merged
merged 1 commit into from
May 31, 2024
Merged
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
5 changes: 4 additions & 1 deletion cms/djangoapps/contentstore/video_storage_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,10 @@ def _get_values(video, course):
for attr in attrs:
if attr == 'courses':
current_course = [c for c in video['courses'] if course_id in c]
(__, values['course_video_image_url']), = list(current_course[0].items())
if current_course:
values['course_video_image_url'] = current_course[0][course_id]
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason you don't keep the original code and just wrap it in a the if/else that you creates here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This seemed better in terms of clarity. I believe using list() and items() iterates twice as well which is worse for performance but that's not a big deal here.

Copy link
Member

Choose a reason for hiding this comment

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

That makes sense. I am still slightly confused why you are indexing the dict with the course_id. Is that how you get the image url? If you could add a comment in to code to clarify this it would help me understand more.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought the video looked like this from working it out backwards. And current_course is only populated with entries if course_id in c.

video = {
  'courses': [
    {
      'course_id_123': 'img.url',
      ...
    },
  ],
}

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the example! It definitely clears up my confusion

else:
values['course_video_image_url'] = None
elif attr == 'encoded_videos':
values['download_link'] = ''
values['file_size'] = 0
Expand Down
Loading