ShivamSharma43 opened a new issue, #9330:
URL: https://github.com/apache/devlake/issues/9330

   ### Search before asking
   
   - [X] I had searched in the 
[issues](https://github.com/apache/devlake/issues?q=is%3Aissue) and found no 
similar issues.
   
   ### What happened
   
   The Tempo `convert_worklogs` subtask 
(`backend/plugins/tempo/tasks/worklog_convertor.go`) builds the 
`issue_worklogs` id from the Tempo worklog id alone:
   
   ```go
   domainWorklogId := fmt.Sprintf("tempo:TempoWorklog:%d", 
tempoWorklog.TempoWorklogId)
   ```
   
   The tool layer keys worklogs by `(connection_id, tempo_worklog_id)` 
(`models.TempoWorklog`), and the other ids of the same row 
(`jira:JiraIssue:<conn>:<id>`, `jira:JiraAccount:<conn>:<id>`) carry the 
connection id. Domain ids that `didgen` generates for other plugins carry it 
too. The worklog id doesn't.
   
   So when two Tempo connections have a worklog with the same `tempoWorklogId` 
(two connections to the same Tempo instance, or two instances whose worklog ids 
overlap), both convert to the same `issue_worklogs` primary key. The connection 
converted last overwrites the other connection's row (its `issue_id`, 
`author_id` and `_raw_data_params`), so one of the two worklogs disappears from 
the domain layer.
   
   Example: connection 1 and connection 2 both have worklog `12345`. After 
converting connection 1 and then connection 2, `issue_worklogs` has one row, 
`tempo:TempoWorklog:12345`, which points to `jira:JiraIssue:2:...`. Connection 
1's worklog is gone. Re-running connection 1 brings it back and drops 
connection 2's.
   
   ### What do you expect to happen
   
   Each connection's worklog gets its own domain row: 
`tempo:TempoWorklog:<connectionId>:<tempoWorklogId>`, the id `didgen` would 
generate from the `TempoWorklog` primary key.
   
   ### How to reproduce
   
   1. Create two Tempo connections (ids 1 and 2) that both return a worklog 
with the same `tempoWorklogId`.
   2. Collect, extract and convert worklogs for a team scope of each connection.
   3. `SELECT id, issue_id, _raw_data_params FROM issue_worklogs WHERE id LIKE 
'tempo:%'` shows one row for that worklog instead of two.
   
   ### Anything else
   
   Proposed fix (I have a PR ready): add the connection id to the domain 
worklog id and add a unit test. No migration is needed: the converter is a 
full-sync `DataConverter`, so its first batch deletes the scope's old rows 
(same `_raw_data_table` / `_raw_data_params`) before it saves the rows with the 
new ids.
   
   ### Version
   
   main
   
   ### Are you willing to submit PR?
   
   - [X] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [X] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to