OpenFn / OpenFn/adaptors

Collections: Having the same key twice in the same payload throws a lightning error

Open
#857 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

DevX Needs Priority
Dominant language
JavaScript
Stars
24
Forks
41
Avg merge
3d 13h
Merged PRs (30d)
12

Description

If I curl this:

 curl -X POST "http://localhost:4000/collections/stuff" -H "Authorization: Bearer $LOCAL_LIGHTNING_PAT" --json @tmp/payload.json^C

With this payload:

{ "key": "aa", "value": "xx" }

We get this exception in Lightning:

Exception:

    ** (Postgrex.Error) ERROR 21000 (cardinality_violation) ON CONFLICT DO UPDATE command cannot affect row a second time

Options:

  1. Detect the issue and throw
  2. Detect the issue, remove dupes and warn

I'm leaning towards 2 here

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure at POST /collections/stuff using tmp/payload.json and the curl command shown. Trace the collection write path that produces the Postgrex cardinality_violation, then confirm the intended duplicate-key behavior with a maintainer. Done means duplicate keys no longer trigger this exception and the chosen handling is covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, postgresql
Domain
database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.