Skip to content

Commit 421a2ec

Browse files
committed
Fix duplicate items when Fastest Delivery sort chosen
Fixes #35 - Products were appearing multiple times when sorted by Fastest Delivery due to JOIN with ProductDeliveryLink creating duplicate rows for products with multiple delivery options. Added .distinct() to all delivery_fastest sorting queries to ensure each product appears only once in the results.
1 parent ce1b798 commit 421a2ec

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

backend/app/main.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ def get_products_api(
231231
).asc(),
232232
cast(ColumnElement[float], Product.price).asc(),
233233
)
234+
.distinct()
234235
)
235236
else:
236237
stmt = (
@@ -242,6 +243,7 @@ def get_products_api(
242243
).asc(),
243244
cast(ColumnElement[float], Product.price).asc(),
244245
)
246+
.distinct()
245247
)
246248
else:
247249
stmt = stmt.order_by(cast(ColumnElement, Product.created_at).desc())
@@ -253,6 +255,7 @@ def get_products_api(
253255
cast(ColumnElement[int], DeliveryOption.estimated_days_min).asc(),
254256
cast(ColumnElement[float], Product.price).asc(),
255257
)
258+
.distinct()
256259
)
257260
elif sort == "price_asc":
258261
stmt = stmt.order_by(cast(ColumnElement[float], Product.price).asc())

0 commit comments

Comments
 (0)