Skip to content

Fix duplicate community library submission#5773

Open
AlexVelezLl wants to merge 1 commit intolearningequality:unstablefrom
AlexVelezLl:fix-community-library-submissions-ordering
Open

Fix duplicate community library submission#5773
AlexVelezLl wants to merge 1 commit intolearningequality:unstablefrom
AlexVelezLl:fix-community-library-submissions-ordering

Conversation

@AlexVelezLl
Copy link
Member

Summary

Fixes community library submission ordering when requesting the latest submission. The error occurred because on the submission side panel, we query the latest submission to know if a submission already exists, but the ordering was set to "-updated_date" by default. Therefore, if a previous submission was recently updated, we will get this previous submission, instead of the "newer created submission". Therefore, allowing the user to make the request to create a submission that already exists.

References

Closes #5766.

Reviewer guidance

  • Create two submissions S1 for version v1, S2 for version v2 for a given channel.
  • Aprove S1.
  • Without publishing any new versions, go to the submission side panel. You should see that a submission for v2 already exists, and shouldn't allow creating a new submission.

Copy link
Contributor

@rtibblesbot rtibblesbot left a comment

Choose a reason for hiding this comment

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

Clean fix for the duplicate submission bug.

CI pending (frontend tests, Python unit tests, linting still running). No UI files changed.

  • praise: Root cause is well-identified — the hardcoded -date_updated ordering caused recently-updated older submissions to shadow newer ones, allowing duplicate creation. The fix correctly separates the default ordering from the queryset and enables client-specified ordering via ValuesViewsetOrderingFilter, which is the established pattern in this codebase.

@rtibblesbot's comments are generated by an LLM, and should be evaluated accordingly

How was this generated?

Reviewed the pull request diff checking for:

  • Correctness: bugs, edge cases, undocumented behavior, resource leaks, hardcoded values
  • Design: unnecessary complexity, naming, readability, comment accuracy, redundant state
  • Architecture: duplicated concerns, minimal interfaces, composition over inheritance
  • Testing: behavior-based assertions, mocks only at hard boundaries, accurate coverage
  • Completeness: missing dependencies, unupdated usages, i18n, accessibility, security
  • Principles: DRY (same reason to change), SRP, Rule of Three (no premature abstraction)
  • Checked CI status and linked issue acceptance criteria
  • For UI changes: inspected screenshots for layout, visual completeness, and consistency

pagination_class = CommunityLibrarySubmissionPagination

ordering_fields = ["date_updated", "date_created"]
ordering = "-date_updated"
Copy link
Contributor

Choose a reason for hiding this comment

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

praise: Good design — setting ordering = "-date_updated" as the viewset default preserves backward compatibility for all other callers while enabling the frontend to override with -date_created when needed.

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.

Unstable - "Duplicate key value violates unique constraint" error

2 participants