n8n-nodes-python icon indicating copy to clipboard operation
n8n-nodes-python copied to clipboard

Report a bug in PythonFunction.node.ts

Open KevinRich651 opened this issue 2 years ago • 8 comments

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); }

KevinRich651 avatar Aug 10 '23 11:08 KevinRich651

I think it should be returnData.items = parseShellOutput(returnData.stdout)

KevinRich651 avatar Aug 10 '23 11:08 KevinRich651

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 ?

naskio avatar Aug 10 '23 14:08 naskio

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
  1. 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.

  2. The failure reason I got on the n8n webpage is out of memory as the screenshot: image

  3. But I the error I got on GCP logging (the n8n is self-hosted on GCP container) as following: image

KevinRich651 avatar Aug 11 '23 03:08 KevinRich651

hi @naskio any ideas about this issue? Thank you in advance.

KevinRich651 avatar Aug 16 '23 10:08 KevinRich651

hi @naskio would you mind to take a brief look at this issue. Perhaps a cue from you will help me a lot.

KevinRich651 avatar Aug 18 '23 03:08 KevinRich651

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).

naskio avatar Aug 18 '23 05:08 naskio

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?

KevinRich651 avatar Aug 18 '23 09:08 KevinRich651

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... image

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

KevinRich651 avatar Aug 25 '23 04:08 KevinRich651