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

fix(Postgres Node): Allow users to wrap strings with $$ #12034

Merged
merged 2 commits into from
Dec 16, 2024

Conversation

dana-gill
Copy link
Contributor

@dana-gill dana-gill commented Dec 4, 2024

Summary

Allow users to wrap strings in $$ instead of quotes

Some Workflows to test:

{
  "nodes": [
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "INSERT INTO dollar_bug (description) VALUES\n($$34loltestytest User data not saving properly$$);",
        "options": {}
      },
      "id": "b180d69a-019e-4cf4-9290-e258dad0bdf9",
      "name": "This is the problem1",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        1240,
        -160
      ],
      "credentials": {
        "postgres": {
          "id": "UeO14x83grJWzgYI",
          "name": "Postgres account 2"
        }
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "INSERT INTO dollar_bug (description) VALUES ($1)",
        "options": {
          "queryReplacement": "$3This is a bug related to the dollar sign $"
        }
      },
      "id": "47474b47-1009-42f3-8654-5bd23dc0a14f",
      "name": "TestCase query param",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        1220,
        20
      ],
      "credentials": {
        "postgres": {
          "id": "UeO14x83grJWzgYI",
          "name": "Postgres account 2"
        }
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "INSERT INTO dollar_bug (description) VALUES ($1 || $$3 hehe more text here$$)",
        "options": {
          "queryReplacement": "$3This is a bug related to the dollar sign $"
        }
      },
      "id": "676dfb87-c756-4091-8b1b-beda7018d040",
      "name": "TestCase query param and string",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 2.5,
      "position": [
        1240,
        200
      ],
      "credentials": {
        "postgres": {
          "id": "UeO14x83grJWzgYI",
          "name": "Postgres account 2"
        }
      }
    }
  ],
  "connections": {},
  "pinData": {}
}

Related Linear tickets, Github issues, and Community forum posts

https://linear.app/n8n/issue/NODE-1673/postgres-dollar-quoted-strings-are-messed-up-on-insertion

Review / Merge checklist

  • PR title and summary are descriptive. (conventions)
  • Docs updated or follow-up ticket created.
  • Tests included.
  • PR Labeled with release/backport (if the PR is an urgent fix that needs to be backported)

In utils, `pgp.helpers.concat`, calls `pg.format` under the hood.
`pg.format` interprets any combination of a dollar sign with a number
(eg: `$1`, `$2`) as a query parameter regardless of a prepended dollar
sign (ie: `$$1` is interpreted as expecting a query parameter in
position 1). We need to allow for partial replacement, which involves
passing in an options object.
@dana-gill dana-gill changed the title fix(Postgres) Allow users to wrap strings with $$ fix(Postgres Node) Allow users to wrap strings with $$ Dec 4, 2024
@dana-gill dana-gill changed the title fix(Postgres Node) Allow users to wrap strings with $$ fix(Postgres Node): Allow users to wrap strings with $$ Dec 4, 2024
Copy link

codecov bot commented Dec 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

@n8n-assistant n8n-assistant bot added n8n team Authored by the n8n team node/improvement New feature or request labels Dec 4, 2024
@dana-gill dana-gill marked this pull request as ready for review December 16, 2024 16:39
Copy link
Contributor

@ShireenMissi ShireenMissi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🎉

Copy link

cypress bot commented Dec 16, 2024

n8n    Run #8364

Run Properties:  status check passed Passed #8364  •  git commit 2154a76ef5: 🌳 🖥️ browsers:node18.12.0-chrome107 🤖 dana-gill 🗃️ e2e/*
Project n8n
Branch Review node-1673-dollar-quote
Run status status check passed Passed #8364
Run duration 04m 37s
Commit git commit 2154a76ef5: 🌳 🖥️ browsers:node18.12.0-chrome107 🤖 dana-gill 🗃️ e2e/*
Committer Dana Lee
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 1
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 478
View all changes introduced in this branch ↗︎

Copy link
Contributor

✅ All Cypress E2E specs passed

@ShireenMissi ShireenMissi merged commit 0c15e30 into master Dec 16, 2024
38 of 44 checks passed
@ShireenMissi ShireenMissi deleted the node-1673-dollar-quote branch December 16, 2024 17:02
@github-actions github-actions bot mentioned this pull request Dec 19, 2024
@janober
Copy link
Member

janober commented Dec 19, 2024

Got released with [email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
n8n team Authored by the n8n team node/improvement New feature or request Released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants