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

Report a bug in PythonFunction.node.ts #12

Open
KevinRich651 opened this issue Aug 10, 2023 · 8 comments
Open

Report a bug in PythonFunction.node.ts #12

KevinRich651 opened this issue Aug 10, 2023 · 8 comments

Comments

@KevinRich651
Copy link

KevinRich651 commented Aug 10, 2023

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
Copy link
Author

KevinRich651 commented Aug 10, 2023

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

@naskio
Copy link
Owner

naskio commented Aug 10, 2023

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 ?

@KevinRich651
Copy link
Author

KevinRich651 commented Aug 11, 2023

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
  1. But I the error I got on GCP logging (the n8n is self-hosted on GCP container) as following:
image

@KevinRich651
Copy link
Author

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

@KevinRich651
Copy link
Author

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

@naskio
Copy link
Owner

naskio commented Aug 18, 2023

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

@KevinRich651
Copy link
Author

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
Copy link
Author

KevinRich651 commented Aug 25, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants