Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions rag/utils/azure_sas_conn.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,22 @@ def health(self):
def put(self, bucket, fnm, binary, tenant_id=None):
for _ in range(3):
try:
return self.conn.upload_blob(name=fnm, data=BytesIO(binary), length=len(binary))
return self.conn.upload_blob(name=f"{bucket}/{fnm}", data=BytesIO(binary), length=len(binary))
except Exception:
logging.exception(f"Fail put {bucket}/{fnm}")
self.__open__()
time.sleep(1)

def rm(self, bucket, fnm):
try:
self.conn.delete_blob(fnm)
self.conn.delete_blob(f"{bucket}/{fnm}")
except Exception:
logging.exception(f"Fail rm {bucket}/{fnm}")

def get(self, bucket, fnm):
for _ in range(1):
try:
r = self.conn.download_blob(fnm)
r = self.conn.download_blob(f"{bucket}/{fnm}")
return r.read()
Comment on lines 69 to 73
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Legacy blobs can become unreadable after this path migration.

Line 72 and Line 82 now only target "{bucket}/{fnm}". Existing unprefixed blobs (fnm) can no longer be found/read, which can break current read paths (e.g., api/utils/image_utils.py:23-27, rag/flow/parser/pdf_chunk_metadata.py:202-206).

Suggested compatibility fallback (read/exist)
 def get(self, bucket, fnm):
-    for _ in range(1):
-        try:
-            r = self.conn.download_blob(f"{bucket}/{fnm}")
-            return r.read()
-        except Exception:
-            logging.exception(f"fail get {bucket}/{fnm}")
-            self.__open__()
-            time.sleep(1)
+    candidates = [f"{bucket}/{fnm}", fnm]
+    for name in candidates:
+        try:
+            r = self.conn.download_blob(name)
+            return r.read()
+        except Exception:
+            continue
+    logging.exception(f"fail get {bucket}/{fnm}")
+    self.__open__()
+    time.sleep(1)
     return

 def obj_exist(self, bucket, fnm):
     try:
-        return self.conn.get_blob_client(f"{bucket}/{fnm}").exists()
+        return (
+            self.conn.get_blob_client(f"{bucket}/{fnm}").exists()
+            or self.conn.get_blob_client(fnm).exists()
+        )
     except Exception:
         logging.exception(f"Fail put {bucket}/{fnm}")
     return False

Also applies to: 80-83

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@rag/utils/azure_sas_conn.py` around lines 69 - 73, The get method in
rag/utils/azure_sas_conn.py currently only tries
self.conn.download_blob(f"{bucket}/{fnm}") which breaks legacy unprefixed blobs;
change get (and the corresponding existence check method that mirrors lines
~80-83) to first attempt the "{bucket}/{fnm}" path and if that fails (catch the
not-found/read error) fall back to trying the raw "fnm" path before giving up,
returning the blob bytes on success; do the same for the exists/existence helper
so callers like image_utils.py and pdf_chunk_metadata.py remain compatible with
legacy keys.

except Exception:
logging.exception(f"fail get {bucket}/{fnm}")
Expand All @@ -79,7 +79,7 @@ def get(self, bucket, fnm):

def obj_exist(self, bucket, fnm):
try:
return self.conn.get_blob_client(fnm).exists()
return self.conn.get_blob_client(f"{bucket}/{fnm}").exists()
except Exception:
logging.exception(f"Fail put {bucket}/{fnm}")
return False
Expand Down
8 changes: 4 additions & 4 deletions rag/utils/azure_spn_conn.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def health(self):
def put(self, bucket, fnm, binary, tenant_id=None):
for _ in range(3):
try:
f = self.conn.create_file(fnm)
f = self.conn.create_file(f"{bucket}/{fnm}")
f.append_data(binary, offset=0, length=len(binary))
return f.flush_data(len(binary))
except Exception:
Expand All @@ -83,14 +83,14 @@ def put(self, bucket, fnm, binary, tenant_id=None):

def rm(self, bucket, fnm):
try:
self.conn.delete_file(fnm)
self.conn.delete_file(f"{bucket}/{fnm}")
except Exception:
logging.exception(f"Fail rm {bucket}/{fnm}")

def get(self, bucket, fnm):
for _ in range(1):
try:
client = self.conn.get_file_client(fnm)
client = self.conn.get_file_client(f"{bucket}/{fnm}")
r = client.download_file()
return r.read()
Comment on lines 90 to 95
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Read/existence paths need a legacy fallback to avoid data invisibility.

Line 93 and Line 104 now only use "{bucket}/{fnm}". Older unprefixed objects can become unreadable/uncheckable immediately after deploy.

Also applies to: 102-105

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@rag/utils/azure_spn_conn.py` around lines 90 - 95, The get method (and
corresponding existence check) currently only tries the prefixed path
f"{bucket}/{fnm}", which will make legacy unprefixed objects inaccessible;
update the get and exists logic in class methods (e.g., get and exists using
self.conn.get_file_client and client.download_file) to attempt the prefixed path
first and, on a NotFound/404 or other read failure, fall back to the legacy
unprefixed path (just f"{fnm}") before returning failure — catch the
download/get exceptions, try the alternate key, and return the result from
whichever succeeds (or propagate a clear error if both fail).

except Exception:
Expand All @@ -101,7 +101,7 @@ def get(self, bucket, fnm):

def obj_exist(self, bucket, fnm):
try:
client = self.conn.get_file_client(fnm)
client = self.conn.get_file_client(f"{bucket}/{fnm}")
return client.exists()
except Exception:
logging.exception(f"Fail put {bucket}/{fnm}")
Expand Down
Loading