Skip to content

Commit b4fca42

Browse files
committed
fix: set _drive_id_endpoint before early return in SharePointReader._get_drive_id
When drive_id is provided directly to SharePointReader, _get_drive_id() returned early without setting _drive_id_endpoint, causing AttributeError in downstream methods like _get_sharepoint_folder_id, _get_permissions_info, _list_folder_contents, and _list_drive_contents. Moved the _drive_id_endpoint assignment before the early return checks so it is always set regardless of how the drive ID is resolved. Bump llama-index-readers-microsoft-sharepoint version to 0.8.1.
1 parent 59b4cc6 commit b4fca42

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

llama-index-integrations/readers/llama-index-readers-microsoft-sharepoint/llama_index/readers/microsoft_sharepoint/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,14 +312,14 @@ def _get_drive_id(self) -> str:
312312
ValueError: If there is an error in obtaining the drive ID.
313313
314314
"""
315+
self._drive_id_endpoint = f"https://graph.microsoft.com/v1.0/sites/{self._site_id_with_host_name}/drives"
316+
315317
if hasattr(self, "_drive_id"):
316318
return self._drive_id
317319

318320
if self.drive_id:
319321
return self.drive_id
320322

321-
self._drive_id_endpoint = f"https://graph.microsoft.com/v1.0/sites/{self._site_id_with_host_name}/drives"
322-
323323
# Use generic pagination helper to get all drives
324324
drives = self._get_all_items_with_pagination(self._drive_id_endpoint)
325325

llama-index-integrations/readers/llama-index-readers-microsoft-sharepoint/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ dev = [
2626

2727
[project]
2828
name = "llama-index-readers-microsoft-sharepoint"
29-
version = "0.8.0"
29+
version = "0.8.1"
3030
description = "llama-index readers microsoft_sharepoint integration"
3131
authors = [{name = "Your Name", email = "you@example.com"}]
3232
requires-python = ">=3.9,<4.0"

llama-index-integrations/readers/llama-index-readers-microsoft-sharepoint/tests/test_readers_microsoft_sharepoint.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,3 +577,32 @@ def test_get_all_items_with_pagination_empty_result():
577577
)
578578

579579
assert len(items) == 0
580+
581+
582+
def test_drive_id_endpoint_set_when_drive_id_provided():
583+
"""
584+
Test that _drive_id_endpoint is set even when drive_id is provided directly.
585+
586+
Regression test for https://github.com/run-llama/llama_index/issues/18753
587+
"""
588+
reader = SharePointReader(
589+
client_id="dummy_client_id",
590+
client_secret="dummy_client_secret",
591+
tenant_id="dummy_tenant_id",
592+
drive_id="my_drive_id",
593+
)
594+
reader._site_id_with_host_name = "dummy_site_id"
595+
596+
# Bypass the autouse _get_drive_id mock by calling the unpatched method directly
597+
# via the descriptor protocol on the original class
598+
import importlib
599+
600+
mod = importlib.import_module("llama_index.readers.microsoft_sharepoint.base")
601+
importlib.reload(mod)
602+
orig_get_drive_id = mod.SharePointReader._get_drive_id
603+
result = orig_get_drive_id(reader)
604+
605+
assert result == "my_drive_id"
606+
assert reader._drive_id_endpoint == (
607+
"https://graph.microsoft.com/v1.0/sites/dummy_site_id/drives"
608+
)

llama-index-integrations/readers/llama-index-readers-microsoft-sharepoint/uv.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)