specify / specify7

Specify 7
https://www.specifysoftware.org/products/specify-7/
GNU General Public License v2.0
62 stars 36 forks source link

Duplicate entry '875-4458' for key 'AgentIDX' when merging agents #2713

Closed maxpatiiuk closed 2 months ago

maxpatiiuk commented 1 year ago
Screenshot 2022-12-27 at 08 26 48

Specify 7 Crash Report - 2022-12-27T14_26_26.175Z.txt

Agent 4458:

{
  "id": 4458,
  "abbreviation": null,
  "agenttype": 1,
  "date1": null,
  "date1precision": null,
  "date2": null,
  "date2precision": null,
  "dateofbirth": null,
  "dateofbirthprecision": null,
  "dateofdeath": null,
  "dateofdeathprecision": null,
  "datetype": null,
  "email": null,
  "firstname": "Kyle",
  "guid": "2b9551ea-2f83-440a-ae74-c70a7a7838ab",
  "initials": null,
  "integer1": null,
  "integer2": null,
  "interests": null,
  "jobtitle": null,
  "lastname": "Orr",
  "middleinitial": "D",
  "remarks": null,
  "suffix": null,
  "text1": null,
  "text2": null,
  "text3": null,
  "text4": null,
  "text5": null,
  "timestampcreated": "2022-11-30T14:33:41",
  "timestampmodified": "2022-12-27T14:25:13.011361",
  "title": null,
  "url": null,
  "verbatimdate1": null,
  "verbatimdate2": null,
  "version": 1,
  "collcontentcontact": null,
  "colltechcontact": null,
  "createdbyagent": "/api/specify/agent/1514/",
  "division": "/api/specify/division/2/",
  "instcontentcontact": null,
  "insttechcontact": null,
  "modifiedbyagent": "/api/specify/agent/1514/",
  "organization": null,
  "specifyuser": null,
  "addresses": [],
  "orgmembers": "/api/specify/agent/?organization=4458",
  "agentattachments": [],
  "agentgeographies": [],
  "identifiers": [],
  "agentspecialties": [],
  "variants": [],
  "collectors": "/api/specify/collector/?agent=4458",
  "groups": [],
  "members": "/api/specify/groupperson/?member=4458",
  "resource_uri": "/api/specify/agent/4458/"
}
maxpatiiuk commented 1 year ago

@acwhite211 happens consistently in the coldFish database (you can download it from the test server)

Does not happen for newmexico and fwri databases

Edit: happened in the newmexico database too

maxpatiiuk commented 1 year ago

@acwhite211 Do you want to discuss potential solutions to this on Monday?

Also, @chanulee1 discovered an issue that is quite related: https://github.com/specify/specify7/pull/2579#issuecomment-1399051961

When merging agents, I modify the canonical record to have the addresses from the duplicates. However, when I call the agent replace endpoint, the endpoint also carries over the dependent records (Address) from the duplicate to the canonical.

(i.e, there was agent 1 with address 1 and agent 2 with address 2. Just before calling back-end, front end modified agent 1 to have both address 1 and agent 2. then, back-end replaces all references to agent 2 with agent 1 - which in effect also makes agent 2's address 2 point at agent 1, and so agent 1 ends up having a duplicate address 2)

Proposed solutions:

grantfitzsimmons commented 1 year ago

@acwhite211 Can you look into this case to see if we can close this issue?

grantfitzsimmons commented 1 year ago

Should be caught by business rules. Close in the future if this is not rediscovered.