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

IF issue. Wrong type ' NNN' is a string but was expecting a number #9493

Closed
barn4k opened this issue May 22, 2024 · 1 comment
Closed

IF issue. Wrong type ' NNN' is a string but was expecting a number #9493

barn4k opened this issue May 22, 2024 · 1 comment

Comments

@barn4k
Copy link

barn4k commented May 22, 2024

Bug Description

I have pretty odd situation with the IF node. I have set it to check if some value is greater than 1, I see that the value is actually a number, but the node keeps saying that it is a string
image

To Reproduce

copy the workflow

{
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "ea8ccd7cb9d9fc233a4683c7569b952c9669ba9d3ba1459d89a9944d357fa5b3"
  },
  "nodes": [
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "5f8d0b3b-b181-4f7f-81e6-dbe9b198cc79",
              "name": "cases",
              "value": "={{ $json.result.total }}",
              "type": "number"
            },
            {
              "id": "0c09d6fd-d232-4cce-bf91-5c5c04fd5b10",
              "name": "cid",
              "value": "={{ $json.result.cases[0].case_id }}",
              "type": "number"
            },
            {
              "id": "3ea2cf36-6c9f-4525-86e1-bb4ffb5974e5",
              "name": "state",
              "value": "={{ $json.result.cases[0].state.state_name }}",
              "type": "string"
            },
            {
              "id": "db3cdb66-1c0b-46e2-bc3e-c7e707d25e38",
              "name": "tags",
              "value": "={{ Object.values($json.result.cases[0].tags).map(t => t.tag_title) }}",
              "type": "array"
            },
            {
              "id": "546dd0da-d597-4a00-8f7a-9f83313c8229",
              "name": "created",
              "value": "={{ DateTime.fromISO($json.result.cases[0].initial_date) }}",
              "type": "string"
            },
            {
              "id": "8d2fbf7c-a8b9-4bde-8e77-5a533ddf1ef6",
              "name": "createdDaysAgo",
              "value": "={{ DateTime.fromISO($json.result.cases[0].initial_date).diffNow('days').toObject().days*-1 }}",
              "type": "number"
            },
            {
              "id": "e3b37e5e-1429-4714-b143-9e9068a2fa2e",
              "name": "modified",
              "value": "={{ DateTime.fromSeconds(parseInt(Object.keys($json.result.cases[0].modification_history).at(-1))) }}",
              "type": "string"
            },
            {
              "id": "be0c2e12-0a86-4977-9a3e-7bd449f7aa9f",
              "name": "modifiedDaysAgo",
              "value": "={{ DateTime.fromSeconds(parseInt(Object.keys($json.result.cases[0].modification_history).at(-1))).diffNow('days').toObject().days*-1 }}",
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "id": "a4351a70-211d-4d60-a505-9439b2c2b2b3",
      "name": "Set case details",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.3,
      "position": [
        560,
        360
      ]
    },
    {
      "parameters": {},
      "id": "7fa70729-b44d-4e2f-8590-ef4ccc3997f9",
      "name": "When clicking \"Test workflow\"",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        300,
        360
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "2cfd182b-d63c-4b8d-a97e-e45662678d64",
              "leftValue": "=\n {{ $json.modifiedDaysAgo }}",
              "rightValue": 1,
              "operator": {
                "type": "number",
                "operation": "gt"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "d92d9681-7597-4dfc-a3ba-d3346c531882",
      "name": "IF case updated >1 day ago",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        820,
        360
      ]
    }
  ],
  "connections": {
    "Set case details": {
      "main": [
        [
          {
            "node": "IF case updated >1 day ago",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \"Test workflow\"": {
      "main": [
        [
          {
            "node": "Set case details",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {
    "Set case details": [
      {
        "cases": 1,
        "cid": 191,
        "state": "Open",
        "tags": [],
        "created": "2024-03-24T03:27:52.811+01:00",
        "createdDaysAgo": 59.671657395833336,
        "modified": "2024-05-22T19:14:36.000+02:00",
        "modifiedDaysAgo": 0.014213090277777778
      }
    ]
  }
}

Expected behavior

the IF node should treat the number as a number...

Operating System

Cloud / Docker

n8n Version

1.41.1

Node.js Version

dunno

Database

SQLite (default)

Execution mode

main (default)

@Joffcom
Copy link
Member

Joffcom commented May 29, 2024

Hey @barn4k,

It looks like your input has a new line character at the start and a space, By removing these string values it is then correctly using a number.

In your JSON this looks like this "=\n {{ $json.modifiedDaysAgo }}", This looks to be more like a typo than a bug. I am going to mark this as closed, Let me know if once removing the extra characters you still have the same issue.

@Joffcom Joffcom closed this as not planned Won't fix, can't repro, duplicate, stale May 29, 2024
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