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

Follow up CSV node msg.columns bug #2853 #4610

Open
dekamerone opened this issue Mar 14, 2024 · 2 comments
Open

Follow up CSV node msg.columns bug #2853 #4610

dekamerone opened this issue Mar 14, 2024 · 2 comments

Comments

@dekamerone
Copy link

dekamerone commented Mar 14, 2024

Current Behavior

see issue #2853:
The issue only occurs if a CSV node is used in a sequence and the columns property of a CSV node is initially empty:
In this case the columns property of a CSV node is set correctly during processing the first part of a sequence.
But the columns property is not updated during the second and other following parts. So, all written data files contain wrong header followed by rows with empty values only.

This behaviour is exactly the same like in closed issue #2853 - obviously the issue was not fixed successfully.

Expected Behavior

For every part in a sequence, the CSV node should not only set the payload to msg.payload but also set the columns property to the current value of msg.columns.

Steps To Reproduce

No response

Example flow

[
    {
        "id": "68f660a4a7502b2c",
        "type": "tab",
        "label": "CSV node test",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "b8022dc8d0633ee5",
        "type": "inject",
        "z": "68f660a4a7502b2c",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 95,
        "y": 200,
        "wires": [
            [
                "306b82b35fb226de"
            ]
        ],
        "l": false
    },
    {
        "id": "306b82b35fb226de",
        "type": "function",
        "z": "68f660a4a7502b2c",
        "name": "Create payload",
        "func": "// table 1 data\nvar table1header = \"ID_Table1,Value_Table1\";\nvar table1Row1 = { \"ID_Table1\": 1, \"Value_Table1\": \"Wert 1\"};\nvar table1Row2 = { \"ID_Table1\": 2, \"Value_Table1\": \"Wert 2\" };\n// table 2 data\nvar table2header = \"ID_Table2,Value_Table2,Value_Table2_2\";\nvar table2Row1 = { \"ID_Table2\": 1, \"Value_Table2\": \"Wert 1\", \"Value_Table2_2\": \"Wert 12\" };\nvar table2Row2 = { \"ID_Table2\": 2, \"Value_Table2\": \"Wert 2\", \"Value_Table2_2\": \"Wert 12\" };\n\nvar table1 = [];\ntable1.push(table1Row1);\ntable1.push(table1Row2);\n\nvar table2 = [];\ntable2.push(table2Row1);\ntable2.push(table2Row2);\n\nvar data = []\ndata.push(table1);\ndata.push(table2);\n\nvar tableHeaders = [];\ntableHeaders.push(table1header);\ntableHeaders.push(table2header);\n\nmsg.payload=data;\nmsg.tableHeaders = tableHeaders;\n\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 260,
        "y": 200,
        "wires": [
            [
                "dadf377990d04693"
            ]
        ]
    },
    {
        "id": "21dc11bb85198e26",
        "type": "debug",
        "z": "68f660a4a7502b2c",
        "name": "debug 12",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 980,
        "y": 200,
        "wires": []
    },
    {
        "id": "dadf377990d04693",
        "type": "split",
        "z": "68f660a4a7502b2c",
        "name": "",
        "splt": "\\n",
        "spltType": "str",
        "arraySplt": 1,
        "arraySpltType": "len",
        "stream": false,
        "addname": "",
        "x": 450,
        "y": 200,
        "wires": [
            [
                "b9da014ad43df1cc"
            ]
        ]
    },
    {
        "id": "d114c0e76b5de4b9",
        "type": "csv",
        "z": "68f660a4a7502b2c",
        "name": "",
        "sep": ",",
        "hdrin": "",
        "hdrout": "all",
        "multi": "one",
        "ret": "\\n",
        "temp": "",
        "skip": "0",
        "strings": true,
        "include_empty_strings": "",
        "include_null_values": "",
        "x": 830,
        "y": 200,
        "wires": [
            [
                "21dc11bb85198e26"
            ]
        ]
    },
    {
        "id": "b9da014ad43df1cc",
        "type": "function",
        "z": "68f660a4a7502b2c",
        "name": "prepareCSVHeaders",
        "func": "msg.columns = msg.tableHeaders[msg.parts.index];\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 640,
        "y": 200,
        "wires": [
            [
                "d114c0e76b5de4b9",
                "314a20f1fc6ddc98"
            ]
        ]
    },
    {
        "id": "314a20f1fc6ddc98",
        "type": "debug",
        "z": "68f660a4a7502b2c",
        "name": "debug 13",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 840,
        "y": 160,
        "wires": []
    }
]

Environment

  • Node-RED version: 3.1.0: Milestone Release
  • Node.js version: v21.2.0
  • npm version: 10.2.3
  • Platform/OS: Windows Server 2016
  • Browser: Edge, Chrome, Firefox
@knolleary
Copy link
Member

Can you provide a simple flow that demonstrates the issue?

@dekamerone
Copy link
Author

Hello together,
I just provided a sample flow with sample data for 2 tables.
With the first table all its ok, with the second table occurs the issue described.
See "debug 12" / msg.payload (contains generated csv string).
Many thanks for your help: Michael

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

No branches or pull requests

2 participants