jshmrtn / hygeia

COVID-19 Tracing
https://info.covid19-tracing.ch/
Other
42 stars 8 forks source link

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

Open sentry-joshmartin-ch[bot] opened 3 years ago

sentry-joshmartin-ch[bot] commented 3 years ago

Sentry Issue: BACKEND-1F7

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

    hint: Ensure that no rows proposed for insertion within the same command have duplicate constrained values.
  File "lib/ecto/adapters/sql.ex", line 760, in Ecto.Adapters.SQL.raise_sql_call_error/1
  File "lib/ecto/adapters/sql.ex", line 667, in Ecto.Adapters.SQL.insert_all/9
  File "lib/ecto/repo/schema.ex", line 58, in Ecto.Repo.Schema.do_insert_all/7
  File "lib/hygeia/import_context.ex", line 87, in anonymous fn/4 in Hygeia.ImportContext.create_import/4
    repo.insert_all(
  File "lib/ecto/multi.ex", line 716, in Ecto.Multi.apply_operation/5
...
(3 additional frame(s) were not displayed)

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

    hint: Ensure that no rows proposed for insertion within the same command have duplicate constrained values.)
maennchen commented 3 years ago

Import Rows are currently identified by the field Fall ID. It should probably be Meldung ID instead.

https://github.com/jshmrtn/hygeia/blob/be2b9ea2d021321031275e8c11aba96ff7afd935/lib/hygeia/import_context/planner/generator/ism_2021_06_11_test.ex#L86

Assumed Bug Reason:

When having two rows in the same import, that reference the same case id, the ON DUPLICATE clause in the insert mutates the same row multiple times. This produces an error.