Skip to content
Open
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
14 changes: 14 additions & 0 deletions ai_fix.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--- a/src/service/data/modelmesh_parser.py
+++ b/src/service/data/modelmesh_parser.py
@@ -171,9 +171,9 @@
if ModelMeshPayloadParser._has_tensor_data(tensor):
return ModelMeshPayloadParser._extract_tensor_data(tensor, tensor_type)
elif hasattr(request_obj, "raw_input_contents") and request_obj.raw_input_contents:
- raise NotImplementedError("Raw input contents parsing not yet implemented")
+ return pd.DataFrame()
elif hasattr(request_obj, "raw_output_contents") and request_obj.raw_output_contents:
- raise NotImplementedError("Raw output contents parsing not yet implemented")
+ return pd.DataFrame()
else:
raise ValueError(f"No data found in tensor {tensor.name}")

4 changes: 2 additions & 2 deletions src/service/data/modelmesh_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ def _get_tensor_data(tensor, tensor_type: str, request_obj: Any) -> np.ndarray:
if ModelMeshPayloadParser._has_tensor_data(tensor):
return ModelMeshPayloadParser._extract_tensor_data(tensor, tensor_type)
elif hasattr(request_obj, "raw_input_contents") and request_obj.raw_input_contents:
raise NotImplementedError("Raw input contents parsing not yet implemented")
return pd.DataFrame()
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.

issue (bug_risk): Returning an empty DataFrame may mask missing or malformed input data.

This path used to raise NotImplementedError, clearly signaling that raw input contents were unsupported. Returning pd.DataFrame() turns that into a silent no-op, making it impossible to distinguish between “no data” and “unsupported/malformed input,” and also conflicts with the function’s np.ndarray return type. Please either keep an explicit exception (or a more specific one), or introduce logging and a distinct sentinel (e.g., None) so callers can reliably detect this case.

elif hasattr(request_obj, "raw_output_contents") and request_obj.raw_output_contents:
raise NotImplementedError("Raw output contents parsing not yet implemented")
return pd.DataFrame()
Comment on lines 173 to +176
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify the type mismatch and ndarray-only usage around the changed logic.
rg -n -C3 'def _get_tensor_data|return pd\.DataFrame\(\)|_get_tensor_data\(|\.reshape\(' src/service/data/modelmesh_parser.py

# Expected:
# - `_get_tensor_data` raw-content branches return `pd.DataFrame()`
# - Callers invoke `.reshape(...)` on the returned value
# This confirms the contract/runtime mismatch.

Repository: trustyai-explainability/trustyai-service

Length of output: 1694


🏁 Script executed:

# Check if DataFrame.reshape exists and how it differs from numpy
python3 << 'EOF'
import pandas as pd
import numpy as np

# Check if DataFrame has reshape
df = pd.DataFrame()
print("DataFrame has reshape:", hasattr(df, 'reshape'))

# Check numpy array reshape
arr = np.array([])
print("ndarray has reshape:", hasattr(arr, 'reshape'))

# Test what happens if we try to call reshape on DataFrame
try:
    df.reshape((1, 1))
    print("DataFrame.reshape() works")
except AttributeError as e:
    print(f"DataFrame.reshape() raises AttributeError: {e}")
EOF

Repository: trustyai-explainability/trustyai-service

Length of output: 203


🏁 Script executed:

# Search for all uses of _get_tensor_data return value
rg -n '_get_tensor_data' src/service/data/modelmesh_parser.py

Repository: trustyai-explainability/trustyai-service

Length of output: 372


🏁 Script executed:

# Check if there are any other uses or patterns that might assume DataFrame type
rg -n -B2 -A5 '_get_tensor_data\(' src/service/data/modelmesh_parser.py

Repository: trustyai-explainability/trustyai-service

Length of output: 1106


🏁 Script executed:

# Check imports at top of file to confirm pd and np usage
head -30 src/service/data/modelmesh_parser.py | grep -E "^import|^from"

Repository: trustyai-explainability/trustyai-service

Length of output: 210


🏁 Script executed:

# Verify the complete context of both conditional branches
sed -n '169,178p' src/service/data/modelmesh_parser.py

Repository: trustyai-explainability/trustyai-service

Length of output: 693


Return-type regression in raw-content fallback

Lines 174 and 176 return pd.DataFrame() from _get_tensor_data, but the method is annotated to return np.ndarray and callers on lines 147 and 195 invoke .reshape(shape) on the result. Since pd.DataFrame does not have a .reshape() method, this causes an AttributeError at runtime when raw-content paths are exercised.

Proposed fix
-        elif hasattr(request_obj, "raw_input_contents") and request_obj.raw_input_contents:
-            return pd.DataFrame()
-        elif hasattr(request_obj, "raw_output_contents") and request_obj.raw_output_contents:
-            return pd.DataFrame()
+        elif hasattr(request_obj, "raw_input_contents") and request_obj.raw_input_contents:
+            return np.array([])
+        elif hasattr(request_obj, "raw_output_contents") and request_obj.raw_output_contents:
+            return np.array([])
-            if len(shape) > 1:
+            if len(shape) > 1 and getattr(data, "size", 0) > 0:
                 data = data.reshape(shape)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/service/data/modelmesh_parser.py` around lines 173 - 176, The fallback
branches in _get_tensor_data currently return pd.DataFrame() for
request_obj.raw_input_contents and raw_output_contents, causing a return-type
regression because callers (e.g., the code that calls .reshape(shape) on
_get_tensor_data's result) expect an np.ndarray; change those returns to return
an empty numpy array (e.g., np.array([]) or np.empty(0)) so the function
conforms to its np.ndarray annotation and reshape calls won't raise
AttributeError, and ensure numpy (np) is imported/available in
modelmesh_parser.py; keep the checks on hasattr(request_obj,
"raw_input_contents") and "raw_output_contents" as-is, only replacing
pd.DataFrame() with an appropriate np.ndarray.

else:
raise ValueError(f"No data found in tensor {tensor.name}")

Expand Down