Fix #35: Prevent duplicate products in Fastest Delivery sort #98
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.
Fixes #35
Problem
Duplicate items were showing when the Fastest Delivery sort option was selected. This occurred because the SQL query joins with the ProductDeliveryLink table, creating duplicate rows when a product has multiple delivery options.
Solution
Added
.distinct()to alldelivery_fastestsorting queries to ensure each product appears exactly once in the results, regardless of how many delivery options it has.Testing
✅ All 51 backend tests pass
✅ All 34 E2E tests pass
✅ All CI checks pass
✅ Tested with and without category filters
✅ Tested with and without delivery option filters
Changes
Modified
/api/productsendpoint inbackend/app/main.py:.distinct()when delivery filter is applied with express speed.distinct()when delivery filter is applied with other speeds.distinct()when no delivery filter is appliedThis ensures no duplicate products appear in any Fastest Delivery sorting scenario.