-
Notifications
You must be signed in to change notification settings - Fork 6
Fix #35: Prevent duplicate products in Fastest Delivery sort #99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -225,6 +225,7 @@ def get_products_api( | |
| stmt = ( | ||
| stmt.join(ProductDeliveryLink) | ||
| .join(DeliveryOption) | ||
| .distinct(cast(Any, Product.id)) | ||
| .order_by( | ||
| cast( | ||
| ColumnElement[int], DeliveryOption.estimated_days_min | ||
|
|
@@ -236,6 +237,7 @@ def get_products_api( | |
| stmt = ( | ||
| stmt.join(ProductDeliveryLink) | ||
| .join(DeliveryOption) | ||
| .distinct(cast(Any, Product.id)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical Bug: Same DISTINCT ON issue as line 228. The |
||
| .order_by( | ||
| cast( | ||
| ColumnElement[int], DeliveryOption.estimated_days_min | ||
|
|
@@ -244,11 +246,12 @@ def get_products_api( | |
| ) | ||
| ) | ||
| else: | ||
| stmt = stmt.order_by(cast(ColumnElement, Product.created_at).desc()) | ||
| stmt = stmt.order_by(cast(ColumnElement[Any], Product.created_at).desc()) | ||
| else: | ||
| stmt = ( | ||
| stmt.join(ProductDeliveryLink) | ||
| .join(DeliveryOption) | ||
| .distinct(cast(Any, Product.id)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical Bug: Same DISTINCT ON issue as lines 228 and 240. The |
||
| .order_by( | ||
| cast(ColumnElement[int], DeliveryOption.estimated_days_min).asc(), | ||
| cast(ColumnElement[float], Product.price).asc(), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical Bug: When using DISTINCT ON with PostgreSQL, the expression in
distinct()must match the first column(s) inorder_by(). Here,distinct(Product.id)is used butorder_by()starts withDeliveryOption.estimated_days_min. This will cause a database error.The correct pattern is:
This same issue appears in all three locations where
.distinct()was added (lines 228, 240, 254).