Skip to content

fix: duplicate courses shown to moderators in created courses list - #2544

Closed
Sandeepambala wants to merge 1 commit into
frappe:developfrom
Sandeepambala:fix/created-courses-duplicate-moderator
Closed

Sandeepambala wants to merge 1 commit into
frappe:developfrom
Sandeepambala:fix/created-courses-duplicate-moderator

Conversation

@Sandeepambala

Copy link
Copy Markdown

The moderator fallback in get_created_courses() runs the base query without the instructor filter. Since the query joins Course Instructor with LMS Course, a course with multiple instructors returns duplicate rows. With limit(3), a single course can occupy all slots in the "Created Courses" section.

Add .distinct() to ensure each course is returned only once.

Fixes #2476

The moderator fallback in get_created_courses() runs the base query
without the instructor filter. Since the query joins Course Instructor
(a child table) with LMS Course, a course with N instructors returns
N identical rows, and with limit(3) a single course can fill every
slot on the Home page's Created Courses section, hiding other courses.

Add .distinct() to the base query so each course appears once.

Fixes: frappe#2476

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5

The changed created-courses query can fail on SQL backends that require ordered columns to be selected with DISTINCT.

  • The new query deduplicates joined rows.
  • It still orders by Course.published_on while selecting only Course.name.
  • That can break the instructor and moderator created-courses path on strict backends.

lms/lms/api.py

Reviews (1): Last reviewed commit: "fix: duplicate courses shown to moderato..." | Re-trigger Greptile

Comment thread lms/lms/api.py
.join(Course)
.on(CourseInstructor.parent == Course.name)
.select(Course.name)
.distinct()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Distinct Orders By Hidden Column

When get_created_courses() runs on PostgreSQL or a strict SQL backend, this can generate SELECT DISTINCT on only Course.name while ordering by Course.published_on. Those backends can reject that query, so the created-courses section can fail for instructors and for the moderator fallback instead of returning courses.

Context Used: Guidelines for reviewing Frappe Framework applicat... (source)

@raizasafeel

Copy link
Copy Markdown
Contributor

Could you please resolve greptile's comments? (comment under the issue if you feel like you disagree)

@raizasafeel

Copy link
Copy Markdown
Contributor

Closing due to inactivity, please reopen with requested changes

@raizasafeel raizasafeel closed this Sep 7, 2026
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.

[Bug] get_created_courses() moderator fallback missing .distinct() causes duplicate course cards on Home page

2 participants