Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fixing crash when no data returned in SAPRFCV2 #887

Merged
merged 2 commits into from
Apr 5, 2024
Merged
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
66 changes: 35 additions & 31 deletions src/viadot/sources/sap_rfc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1162,39 +1162,43 @@ def to_df(self, tests: dict = None):
)
else:
raise e
record_key = "WA"
data_raw = np.array(response["DATA"])
del response

# if the reference columns are provided not necessary to remove any extra row.
if not isinstance(self.rfc_unique_id[0], str):
row_index, data_raw, start = detect_extra_rows(
row_index, data_raw, chunk, fields
)
else:
start = False

records = [row for row in gen_split(data_raw, sep, record_key)]
del data_raw
# Check and skip if there is no data returned
if response["DATA"]:
record_key = "WA"
data_raw = np.array(response["DATA"])
del response

if (
isinstance(self.rfc_unique_id[0], str)
and not list(df.columns) == fields
):
df_tmp = pd.DataFrame(columns=fields)
df_tmp[fields] = records
# SAP adds whitespaces to the first extracted column value
# If whitespace is in unique column it must be removed to make a proper merge
for col in self.rfc_unique_id:
df_tmp[col] = df_tmp[col].str.strip()
df[col] = df[col].str.strip()
df = pd.merge(df, df_tmp, on=self.rfc_unique_id, how="outer")
else:
if not start:
df[fields] = records
# if the reference columns are provided not necessary to remove any extra row.
if not isinstance(self.rfc_unique_id[0], str):
row_index, data_raw, start = detect_extra_rows(
row_index, data_raw, chunk, fields
)
else:
start = False

records = [row for row in gen_split(data_raw, sep, record_key)]
del data_raw

if (
isinstance(self.rfc_unique_id[0], str)
and not list(df.columns) == fields
):
df_tmp = pd.DataFrame(columns=fields)
df_tmp[fields] = records
# SAP adds whitespaces to the first extracted column value
# If whitespace is in unique column it must be removed to make a proper merge
for col in self.rfc_unique_id:
df_tmp[col] = df_tmp[col].str.strip()
df[col] = df[col].str.strip()
df = pd.merge(df, df_tmp, on=self.rfc_unique_id, how="outer")
else:
df[fields] = np.nan
chunk += 1
if not start:
df[fields] = records
else:
df[fields] = np.nan
chunk += 1
elif not response["DATA"]:
print("No data returned from SAP.")
df.columns = columns

if self.client_side_filters:
Expand Down
Loading