exclude topics with no associated channel in api responses #1693
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What are the relevant tickets?
Closes https://github.com/mitodl/hq/issues/5775
Description (What does it do?)
This PR configures
filter_querysetonTopicViewSetto exclude topics wherechannel_urlis null, meaning that the Topic has no associated channel. This has the effect of filtering out these topics from API responses, preventing errors related to accessingchannel_urlwhere it might not exist.How can this be tested?
Firstly, make sure you have data backpopulated in your database relating to courses, topics and channels. You will need both a
LearningResourceTopicwithout and with an associatedChannelobject. The "AR/VR/MR/XR" topic had no channel for me, so either try and use that topic for testing or use a Django shell to ensure that you have the required data. Your user should also be a user withis_stafforis_superuserset to true.To reproduce the issue:
mainbranch ofmit-learnChannelchannel_urlTo see the fix in action:
mit-learnChanneldoes not even appear in the list of topics you can choose from