apache / apache/devlake

JiraIssueChangelogItems primary key collision when Jira reports multiple items with the same field in one changelog entry

Offen
#9,057 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Go
Sterne
3.1k
Forks
808
Ø Merge
1 T. 18 Std.
Gemergte PRs (30 T.)
50

Beschreibung

### Summary

`JiraIssueChangelogItems` has a composite primary key of `(ConnectionId, ChangelogId, Field)`. When Jira returns multiple items with the same `Field` value within a single changelog history entry, the second item silently overwrites the first on upsert.

### Steps to reproduce

1. Have a Jira issue where a single-value field (e.g. `fixVersions`) is changed from value A to value B in one action
2. Jira's API represents this as two changelog items in the same history entry:
- `Fix Version: null → B` (add)
- `Fix Version: A → null` (remove)
3. Both items share the same `ChangelogId` and `Field = "Fix Version"`
4. Run the Jira extractor — only one item survives in `_tool_jira_issue_changelog_items`

### Expected behavior

Both changelog items should be stored — the add and the remove.

### Actual behavior

The second item overwrites the first because they collide on the primary key `(ConnectionId, ChangelogId, Field)`.

### Impact

Any downstream query that relies on changelog items to detect whether a specific value was ever added to a field (e.g. filtering issues by historical `fixVersions`) will produce incorrect results. This affects `fixVersions`, `labels`, `components`, `affectedVersions`, and any other field where Jira emits multiple items with the same field name in one history entry.

### Suggested fix

Add a disambiguating column to the primary key — for example an item ordinal/index within the changelog entry. The model is in `backend/plugins/jira/models/issue_changelog.go`:

```go
type JiraIssueChangelogItems struct {
ConnectionId uint64 `gorm:"primaryKey"`
ChangelogId uint64 `gorm:"primaryKey"`
Field string `gorm:"primaryKey"`
// no item-level disambiguator
}
```

Existing data would need re-extraction after the schema change, since collided rows already lost one of the two items.

### Version

Verified on `v1.0.3-beta10` and confirmed the PK is unchanged on `main` as of 2026-08-17.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Rechercherichtung

Beginne mit backend/plugins/jira/models/issue_changelog.go und verfolge dann den Upsert-Pfad des Jira-Extractors für JiraIssueChangelogItems. Reproduziere die beiden Items mit demselben Feld und untersuche die Auswirkungen der Schemaänderung; als erledigt gilt die Aufgabe, wenn beide Items nach einer erneuten Extraktion ohne Kollision persistiert werden, mit einer Regression-Abdeckung für den gemeldeten Fall.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
go
Bereich
backend, data-engineering, databases
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Aktiv
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
64/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.