You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to be able to create an issue that is a subtask of a different issue. The Jira API supports setting the parent by issue ID or by issue key. However, the way the IssueFields.Parent struct marshals to JSON when only a Key is present prevents Jira from being able to find the issue by key.
To Reproduce
Attempt to create an issue with a parent using only the Key of the parent issue, excluding the ID. The problem can be seen by marshaling an Issue to json:
// attempt to create a subissue on TEST-42issue:= jira.Issue{
Fields: &jira.IssueFields{
Summary: "My Test Issue",
Description: "This issue marshalls to JSON with a parent that Jira does not like.",
Type: jira.IssueType{Name: "Subtask"},
Project: jira.Project{Key: "TEST"},
Parent: &jira.Parent{Key: "TEST-42"},
},
}
// marshall it to JSONj, _:=json.Marshal(issue)
fmt.Println(string(j))
output:
{"fields": {"description": "This issue marshalls to JSON with a parent that Jira does not like.","issuetype": {"name": "Subtask"},"parent": {"id": "",// <-- this empty string prevents Jira from finding the parent ticket"key": "TEST-42"},"project": {"key": "TEST"},"summary": "My Test Issue"}}
When the above issue is passed to client.Issue.Create, Jira responds with {"errorMessages":[],"errors":{"parent":"Could not find issue by id or key."}} despite the fact that the parent ticket (TEST-42) exists.
Expected behavior
The above Parent struct should marshal to { "key": "TEST-42" } (no id). When that payload is passed to Jira it correctly finds the parent issue.
Possible Solution
I recognize this may be a limitation of the way go marshals structs to json. Ideally, Parent would contain pointers to strings so that they could be nil and then be correctly omitted by json.Marshal.
Your Environment
go-jira version (git tag or sha): v1.14.0
Go version (go version): 1.16.6
Jira type (cloud or on-premise): cloud
Additional context
I am open to other solutions. I am able to create the issue as a subtask by including the ID, it is just one more piece of information i'd rather not carry around. Thank you for your time and great client!
The text was updated successfully, but these errors were encountered:
pirtleshell
changed the title
Unable to set parent by key (without issue ID)
Unable to create issue with parent by parent issue key (without parent issue ID)
Dec 8, 2021
Hi! Thank you for taking the time to create your first issue! Really cool to see you here for the first time. Please give us a bit of time to review it.
Describe the bug
I'd like to be able to create an issue that is a subtask of a different issue. The Jira API supports setting the parent by issue ID or by issue key. However, the way the
IssueFields.Parent
struct marshals to JSON when only aKey
is present prevents Jira from being able to find the issue by key.To Reproduce
Attempt to create an issue with a parent using only the
Key
of the parent issue, excluding theID
. The problem can be seen by marshaling anIssue
to json:output:
When the above
issue
is passed toclient.Issue.Create
, Jira responds with{"errorMessages":[],"errors":{"parent":"Could not find issue by id or key."}}
despite the fact that the parent ticket (TEST-42) exists.Expected behavior
The above
Parent
struct should marshal to{ "key": "TEST-42" }
(noid
). When that payload is passed to Jira it correctly finds the parent issue.Possible Solution
I recognize this may be a limitation of the way go marshals structs to json. Ideally,
Parent
would contain pointers to strings so that they could benil
and then be correctly omitted byjson.Marshal
.Your Environment
go version
): 1.16.6Additional context
I am open to other solutions. I am able to create the issue as a subtask by including the ID, it is just one more piece of information i'd rather not carry around. Thank you for your time and great client!
The text was updated successfully, but these errors were encountered: