Skip to content

Commit 19be8a2

Browse files
committed
fix(discourse-connector): handle redirect issue with categoryId rewriting page number
1 parent ab7a418 commit 19be8a2

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

backend/onyx/connectors/discourse/connector.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def __init__(
6060
self.base_url = base_url
6161

6262
self.categories = [c.lower() for c in categories] if categories else []
63-
self.category_id_map: dict[int, str] = {}
63+
self.category_id_map: dict[int, dict] = {}
6464

6565
self.batch_size = batch_size
6666
self.permissions: DiscoursePerms | None = None
@@ -83,7 +83,7 @@ def _get_categories_map(
8383
)
8484
categories = response.json()["category_list"]["categories"]
8585
self.category_id_map = {
86-
cat["id"]: cat["name"]
86+
cat["id"]: {"name": cat["name"], "slug": cat["slug"]}
8787
for cat in categories
8888
if not self.categories or cat["name"].lower() in self.categories
8989
}
@@ -116,7 +116,7 @@ def _get_doc_from_topic(self, topic_id: int) -> Document:
116116
sections.append(
117117
TextSection(link=topic_url, text=parse_html_page_basic(post["cooked"]))
118118
)
119-
category_name = self.category_id_map.get(topic["category_id"])
119+
category_name = self.category_id_map.get(topic["category_id"], {}).get("name")
120120

121121
metadata: dict[str, str | list[str]] = (
122122
{
@@ -158,9 +158,10 @@ def _get_latest_topics(
158158
topics = []
159159
empty_categories = []
160160

161-
for category_id in self.category_id_map.keys():
161+
for category_id, category_dict in self.category_id_map.items():
162162
category_endpoint = urllib.parse.urljoin(
163-
self.base_url, f"c/{category_id}.json?page={page}&sys=latest"
163+
self.base_url,
164+
f"c/{category_dict['slug']}/{category_id}.json?page={page}&sys=latest",
164165
)
165166
response = self._make_request(endpoint=category_endpoint)
166167
new_topics = response.json()["topic_list"]["topics"]

0 commit comments

Comments
 (0)