Canvas connector drops whole courses when the Pages tool is disabled
Version: v4.7.3 (Docker, stock images). Same code on main as of 6a3e5ac.
Problem
When a course has the Pages tool turned off, the connector skips the whole course, including its assignments and announcements. Those documents are never indexed.
Why
Canvas lets teachers remove tools from a course. For those courses it answers GET /courses/{id}/pages with 404 {"message":"That page has been disabled for this course"}.
The connector treats that 404 as "the course is gone". It records a failure and skips the whole course, including assignments and announcements that work. Once more than 3 failures pile up with few documents indexed, Onyx aborts the run with Not Found.
Pruning and permission sync fail with the same Not Found.
Reproduce
I used a local Canvas LMS (instructure/canvas-lms, Docker) with one student enrolled in 5 courses. Each course has 2 assignments and 1 announcement. Course 5 also has 1 page. Pages is turned off in courses 1 to 4 (Settings > Navigation), so the expected total is 16 documents.
With the student's token, Canvas answers GET /courses/{1..4}/pages with the 404 above, and /assignments with 200.
Result on v4.7.3:
- The first attempt fails with
Not Foundand 0 documents. - The automatic retry finishes as "completed with errors" with 4 documents, all from course 5.
- The connector page shows "Some documents failed to index". "View details" lists
Canvas course <id> not found: Not Foundfor courses 1 to 4. - The 12 assignments and announcements of courses 1 to 4 are never indexed.
- The slim-docs path (pruning) fails with
OnyxError: Not Found.
v4.7.3: only 4 of 16 documents indexed, with the "Some documents failed to index" banner.
v4.7.3: the indexing errors. Courses 1 to 4 are reported as "not found", although only their Pages tool is disabled.
Failing unit test (no Canvas account needed)from unittest.mock import patch
from onyx.connectors.canvas.connector import (
CanvasConnector,
CanvasConnectorCheckpoint,
CanvasStage,
)
from onyx.connectors.models import ConnectorFailure
from onyx.error_handling.error_codes import OnyxErrorCode
from onyx.error_handling.exceptions import OnyxError
def test_disabled_pages_tool_does_not_fail_the_course() -> None:
connector = CanvasConnector(canvas_base_url="https://canvas.example.edu")
checkpoint = CanvasConnectorCheckpoint(
has_more=True,
course_ids=[1, 2],
current_course_index=0,
stage=CanvasStage.PAGES,
)
err = OnyxError(
OnyxErrorCode.NOT_FOUND,
"That page has been disabled for this course",
status_code_override=404,
)
with patch.object(connector, "_fetch_stage_page", side_effect=err):
gen = connector._load_from_checkpoint(0, 1e10, checkpoint)
items = []
while True:
try:
items.append(next(gen))
except StopIteration as done:
new_checkpoint = done.value
break
# No failure is recorded, and the same course moves on to its next stage.
assert not any(isinstance(i, ConnectorFailure) for i in items)
assert new_checkpoint.current_course_index == 0
assert new_checkpoint.stage == CanvasStage.ASSIGNMENTSIt fails on main and passes with the fix in #15291.
Fix
A 404 should skip only that tool, and the connector should go on to the course's other content. I have this in #15291.
Source: onyx-dot-app/onyx