n8n-nodes-python
n8n-nodes-python copied to clipboard
Report a bug in PythonFunction.node.ts
hi Naskio,
I encountered a troublesome issue in the n8n. I think it might be a bug in this code
In line 195, the code 0 represent success, but the stderr will be parse.
if (!code) { returnData.items = parseShellOutput(returnData.stderr); } else { returnData.error = new Error(returnData.stderr); }
I think it should be
returnData.items = parseShellOutput(returnData.stdout)
Hi @KevinRich651 You can read this section on README https://github.com/naskio/n8n-nodes-python#notes Actually, the stderr is the one used to pass data the between if the code == 0 otherwise stderr will represent an error. Could you please provide more details such as your code and the error you are getting ?
hi @naskio
Many thanks for your reply. Just now I read the note in Readme. Yes, the code logic is as you described.
The entire python code is huge. I removed the irrelevant code, only left the key part related to this issue. The code is as following:
# Get latest filename
filename_query = "SELECT filename......."
####......
print(new_filename)
# 5. Create points file based on rewards, aggregated by ABN & Name
##.........
# 6. Save points file
##...........
# 7. Add new rewards to GBQ table if file sent successfully saved
##...........
# 8. Update log table
points_amt = all_points_owed['points_amt'].sum()
query_string = f"""
INSERT INTO ..........
"""
update = client.query(query_string).result()
fileNames = [{'filename':new_filename}]
print(fileNames)
return fileNames #CHANGE
-
In the above code,
print(fileNames)can be executed normally, and the fileNames is as expected:[{'filename': 'AWALLX03P.079'}]But this python node still failed. -
The failure reason I got on the n8n webpage is out of memory as the screenshot:
-
But I the error I got on GCP logging (the n8n is self-hosted on GCP container) as following:
hi @naskio any ideas about this issue? Thank you in advance.
hi @naskio would you mind to take a brief look at this issue. Perhaps a cue from you will help me a lot.
Hi @KevinRich651 I don't think that the error is related to this package. I suggest that you move all the code related to read/write data to DB outside the PythonNode and keep only the processing part in the PythonNode, and move the queries to different nodes (You may find other nodes that will simplify the integration with the DB).
Thanks for your suggestion. I will take a try.
I am still confused why the error response in n8n web page and cloud logging is totally different?
hi @naskio I located the accurate line, which triggers the failure. I have never encountered so weird a issue...
try:
# Bonus points offer, valid for KYC Pass Date >= 2023-06-01 & <= 2023-07-31
qbr_eofy_new = all_data.copy()
qbr_eofy_new = qbr_eofy_new[(qbr_eofy_new['kyc_pass_date']>=date(2023,6,1)) & (qbr_eofy_new['kyc_pass_date']<=date(2023,7,31))]
qbr_eofy_new100k = qbr_eofy_new[(qbr_eofy_new['f_60_aud_fx_volume']>=50000)]
qbr_eofy_new100k['points_owed_to_date'] = 100000
except:
print("error")
print(qbr_eofy_new100k)
print(items)
return items
In the above code, all_data is a pandas Dataframe containing hundreds of rows.
It can run normally and output what I expect, no error log and items is a valid json array from the previous node.
But the workflow node PythonFunction containing the code still fail for an unknown reason...
But if I comment or remove the line qbr_eofy_new100k['points_owed_to_date'] = 100000
The workflow can function normally without any error... I have no idea what's wrong with such a simple code.
I run the above code in local environment, the code also runs normally.
My thoughts:
In the GCP logging, I still get the same error as I attached couple weeks ago.
But now I think that error SyntaxError: Unexpected token / in JSON at position 0 is not the root cause.
the return value items in the code didn't really return.
What weird! Hope to get some suggestions from you