fix : Exclude unpublished courses from catalog content metadata API #1127
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.
Root cause:-
The the active status filtering was conditionally applied only when no [content_keys_filter] was provided. When specific content keys were requested, the filtering was skipped, allowing inactive courses to slip through.
Changes:-
-Removed the conditional check: Eliminated the if not content_keys_filter: block
to ensure filtering runs unconditionally.
-Unindented the filtering logic: Moved the queryset = [item for item in queryset if self.is_active(item)]
and related debug logging outside the conditional, so it's executed for all requests.
-Updated the comment: Changed to # Always filter out inactive courses to ensure only active content is always returned via API.
-Added unit tests to verify inactive courses are filtered out, and all the test cases were successful.