From 706f957ba2e2ec7562635b63e7ebd534eeb353be Mon Sep 17 00:00:00 2001 From: furkanyigit34 <134547018+furkanyigit34@users.noreply.github.com> Date: Sat, 25 Apr 2026 16:38:13 +0300 Subject: [PATCH] fix(scraper): pathModel -x-c{id} suffix + defensive int cast MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ne yaptık: - queue_worker.py find_leaves: kategori URL'sine -x-c{id} suffix ekledik (ör: makyaj-cantasi -> makyaj-cantasi-x-c1110) - scraper.py fetch_all_products: total degeri str gelirse int'e cast ediyoruz (roughTotal "0" string donuyordu, '/' operatoru patliyordu) Neden yaptık: - Trendyol Search API path formati degisti, artik suffix'siz cagri 0 urun donduruyor (ornek test: makyaj-cantasi=0, makyaj-cantasi-x-c1110=15.712) - Yan etki olarak 'total' int 0 falsy oldugu icin 'or' chain roughTotal'a dusuyor, bu da string olarak donuyor ve math.ceil(str/int) TypeError firlatiyordu. Tum 35 alt kategori bu yuzden patladi (rapor 62 "Makyaj Analizi" sifir urun). - Fix iki seviyeli: asil cozum suffix (artik dogru data ceker), defansif int() cast gelecekte API'nin baska sekilde tutarsiz donmesine karsi guvenlik agi. Co-Authored-By: Claude Opus 4.7 (1M context) --- backend/queue_worker.py | 4 +++- backend/scraper.py | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/backend/queue_worker.py b/backend/queue_worker.py index b5851e6..3cba263 100644 --- a/backend/queue_worker.py +++ b/backend/queue_worker.py @@ -122,7 +122,9 @@ class QueueWorker: if not children: cat = tree_by_id.get(parent_id) if cat: - path_model = (cat.get("url") or "").lstrip("/") or None + url_slug = (cat.get("url") or "").lstrip("/") + # Trendyol Search API now requires -x-c{id} suffix on pathModel + path_model = f"{url_slug}-x-c{cat['id']}" if url_slug else None return [(path_model, cat["name"], cat["id"])] return [] leaves = [] diff --git a/backend/scraper.py b/backend/scraper.py index 3e0427c..6e7801e 100644 --- a/backend/scraper.py +++ b/backend/scraper.py @@ -210,7 +210,11 @@ class TrendyolSearchScraper: if not first: return [] - total = first.get("total", 0) or first.get("totalCount", 0) or first.get("roughTotal", 0) + total_raw = first.get("total") or first.get("totalCount") or first.get("roughTotal") or 0 + try: + total = int(total_raw) + except (ValueError, TypeError): + total = 0 raw_products = first.get("products", []) if total == 0 and not raw_products: