Skip to content

Resolve Agent Merging Failure due to Agent Specialties #8518

Description

@bronwyncombs

Describe the bug
A clear and concise description of what the bug is.

An agent merge where at least one agent has one or more agent specialty records will fail with the following message:

django.db.utils.IntegrityError: (1062, "Duplicate entry '15400-1' for key 'AgentID'"

see full crash attached below.

Expected behavior
A clear and concise description of what you expected to happen.

Merge without error

Crash Report

Merging 135c3ba5-3263-47a7-ae5c-7b1458e88bd8 Crash Report - 2026-09-09T08_49_18.248Z.txt

Merging ba30975d-8485-46ef-9510-40a1e67ec6b8 Crash Report - 2026-09-09T08_48_33.089Z.txt

Please fill out the following information manually:

  • OS: macOS
  • Browser: chrome
  • Specify 7 Version: 7.12.1.1
  • Database Name: herb-rbge

Reported By
Royal Botanic Garden of Edinburgh

Additional context
related to #5267

also, @melton-jason on this:

I did some quick looking into this Issue.
Both errors are of the form "Duplicate entry 'xxx-y' for key 'AgentID'", which indicate Specify is violating a unique composite key in the database which contains two columns (the field values for these columns is separated by hyphen in the error) and is called AgentID.

I ran the following Query on their database to identify potential tables/columns to help narrow some things down: SELECT TABLE_NAME,
INDEX_NAME,
GROUP_CONCAT(COLUMN_NAME ORDER BY SEQ_IN_INDEX) as columns
FROM information_schema.STATISTICS
WHERE TABLE_SCHEMA = 'herb_rbge'
AND INDEX_NAME = 'AgentID'
GROUP BY TABLE_NAME, INDEX_NAME
HAVING SUM(SEQ_IN_INDEX) >= 3;Below are the results:+----------------+------------+---------------------------+
| TABLE_NAME | INDEX_NAME | columns |
+----------------+------------+---------------------------+
| agentspecialty | AgentID | AgentID,OrderNumber |
| collector | AgentID | AgentID,CollectingEventID |
| determiner | AgentID | AgentID,DeterminationID |
| extractor | AgentID | AgentID,DNASequenceID |
| fundingagent | AgentID | AgentID,CollectingTripID |
| pcrperson | AgentID | AgentID,DNASequenceID |
+----------------+------------+---------------------------+Given that both of the values for the second column (y) are very small (0 and 1), I would assume the violating key/index here is AgentID on AgentSpeciality (thus the second column, y, would be OrderNumber).

So in both cases I think Specify is probably trying to re-insert the Agent's AgentSpecialty when it still exists on the Agent, resulting in the violated key constraint.

For whomever looks at this Issue next, could you go through the code and verify that hypothesis? This might be a somewhat larger issue with dependent relationships in general, where there's a brief window of duplicate dependent records

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    2 - Database/SchemaIssues that are related to the underlying database and schema2 - Merging

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions