Repository: getsentry/sentry

Issue:
I get error Option value 'ID' is not valid in required field in Jira


## Description

[What happened]
when I try to link Jira issue  get this error when filling the data https://monosnap.com/file/Ou1EIPjQhnzYYCVnNkghpgDXXqmDfu
Feature filed is a custom field that we added in Jira
it's required and it has a drop down with a list of option.
When I select any of the options I get this error. https://monosnap.com/file/Ou1EIPjQhnzYYCVnNkghpgDXXqmDfu

 I cannot figure it out why is not valid.







Discussion:
What kind of field are you using in Jira? You might need to look at the issue create meta API response.
it's a select field with multiple choices
https://monosnap.com/file/dnoi4mh6VaJt1f8RAO5sYr2yXlVawR

On Tue, Apr 30, 2019 at 10:34 PM Mark Story <notifications@github.com>
wrote:

> What kind of field are you using in Jira? You might need to look at the
> issue create meta API response.
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/getsentry/sentry/issues/13001#issuecomment-488085531>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AK5DCXNLMVCJZQ3Y767LYZDPTCNN5ANCNFSM4HJPPQ3Q>
> .
>


-- 


[image: photo]
Olya Moskal
Project Manager at 15Five
Email olya@15five.com  <olya@15five.com>
Website https://www.15five.com/
<https://www.15five.com/?utm_source=WiseStamp&utm_medium=email&utm_term=&utm_content=&utm_campaign=signature>

<https://www.facebook.com/15Five?utm_source=WiseStamp&utm_medium=email&utm_term=&utm_content=&utm_campaign=signature>
<https://twitter.com/15Five?utm_source=WiseStamp&utm_medium=email&utm_term=&utm_content=&utm_campaign=signature>
<https://www.15five.com/blog?utm_source=WiseStamp&utm_medium=email&utm_term=&utm_content=&utm_campaign=signature>
Learn Why Our Customers Love Us
<https://www.15five.com/customer-stories/?utm_source=WiseStamp&utm_medium=email&utm_term=&utm_content=&utm_campaign=signature>
<https://www.g2crowd.com/products/15five-continuous-performance-management/reviews?utm_source=WiseStamp&utm_medium=email&utm_term=&utm_content=&utm_campaign=signature>

where I can find this  "You might need to look at the issue create meta API
response."

On Tue, Apr 30, 2019 at 10:40 PM Olya Moskal <olya@15five.com> wrote:

> it's a select field with multiple choices
> https://monosnap.com/file/dnoi4mh6VaJt1f8RAO5sYr2yXlVawR
>
> On Tue, Apr 30, 2019 at 10:34 PM Mark Story <notifications@github.com>
> wrote:
>
>> What kind of field are you using in Jira? You might need to look at the
>> issue create meta API response.
>>
>> —
>> You are receiving this because you authored the thread.
>> Reply to this email directly, view it on GitHub
>> <https://github.com/getsentry/sentry/issues/13001#issuecomment-488085531>,
>> or mute the thread
>> <https://github.com/notifications/unsubscribe-auth/AK5DCXNLMVCJZQ3Y767LYZDPTCNN5ANCNFSM4HJPPQ3Q>
>> .
>>
>
>
> --
>
>
> [image: photo]
> Olya Moskal
> Project Manager at 15Five
> Email olya@15five.com  <olya@15five.com>
> Website https://www.15five.com/
> <https://www.15five.com/?utm_source=WiseStamp&utm_medium=email&utm_term=&utm_content=&utm_campaign=signature>
>
>
> <https://www.facebook.com/15Five?utm_source=WiseStamp&utm_medium=email&utm_term=&utm_content=&utm_campaign=signature>
> <https://twitter.com/15Five?utm_source=WiseStamp&utm_medium=email&utm_term=&utm_content=&utm_campaign=signature>
> <https://www.15five.com/blog?utm_source=WiseStamp&utm_medium=email&utm_term=&utm_content=&utm_campaign=signature>
> Learn Why Our Customers Love Us
> <https://www.15five.com/customer-stories/?utm_source=WiseStamp&utm_medium=email&utm_term=&utm_content=&utm_campaign=signature>
>
> <https://www.g2crowd.com/products/15five-continuous-performance-management/reviews?utm_source=WiseStamp&utm_medium=email&utm_term=&utm_content=&utm_campaign=signature>
>


-- 


[image: photo]
Olya Moskal
Project Manager at 15Five
Email olya@15five.com  <olya@15five.com>
Website https://www.15five.com/
<https://www.15five.com/?utm_source=WiseStamp&utm_medium=email&utm_term=&utm_content=&utm_campaign=signature>

<https://www.facebook.com/15Five?utm_source=WiseStamp&utm_medium=email&utm_term=&utm_content=&utm_campaign=signature>
<https://twitter.com/15Five?utm_source=WiseStamp&utm_medium=email&utm_term=&utm_content=&utm_campaign=signature>
<https://www.15five.com/blog?utm_source=WiseStamp&utm_medium=email&utm_term=&utm_content=&utm_campaign=signature>
Learn Why Our Customers Love Us
<https://www.15five.com/customer-stories/?utm_source=WiseStamp&utm_medium=email&utm_term=&utm_content=&utm_campaign=signature>
<https://www.g2crowd.com/products/15five-continuous-performance-management/reviews?utm_source=WiseStamp&utm_medium=email&utm_term=&utm_content=&utm_campaign=signature>

https://docs.atlassian.com/software/jira/docs/api/REST/8.1.0/#api/2/issue-getCreateIssueMeta is the API call sentry uses to get metadata on how to render inputs for your jira issues.
The metadata of the field from the create meta API response:

```json
{
  "required": true,
  "schema": {
    "type": "array",
    "items": "option",
    "custom": "com.atlassian.jira.plugin.system.customfieldtypes:multiselect",
    "customId": 12345
  },
  "name": "Feature",
  "key": "customfield_12345",
  "hasDefaultValue": false,
  "operations": [
    "add",
    "set",
    "remove"
  ],
  "allowedValues": [
    {
      "self": "https://15five-dev.atlassian.net/rest/api/2/customFieldOption/10001",
      "value": "Feature 1",
      "id": "10001"
    },
    {
      "self": "https://15five-dev.atlassian.net/rest/api/2/customFieldOption/10002",
      "value": "Feature 2",
      "id": "10002"
    },
    {
      "self": "https://15five-dev.atlassian.net/rest/api/2/customFieldOption/10003",
      "value": "Feature 3",
      "id": "10003"
    }
  ]
}
```
Thank you for that, are you running sentry locally or using the saas service?
We are using the saas service.

Resolving patch:
diff --git a/src/sentry/integrations/jira/integration.py b/src/sentry/integrations/jira/integration.py
--- a/src/sentry/integrations/jira/integration.py
+++ b/src/sentry/integrations/jira/integration.py
@@ -319,9 +319,11 @@ def make_choices(self, values):
             if 'name' in item:
                 value = item['name']
             elif 'value' in item:
+                # Value based options prefer the value on submit.
+                key = item['value']
                 value = item['value']
             elif 'label' in item:
-                # Label based options are appear to prefer the value on submit.
+                # Label based options prefer the value on submit.
                 key = item['label']
                 value = item['label']
             else:


Test patch:
diff --git a/tests/sentry/integrations/jira/test_integration.py b/tests/sentry/integrations/jira/test_integration.py
--- a/tests/sentry/integrations/jira/test_integration.py
+++ b/tests/sentry/integrations/jira/test_integration.py
@@ -73,6 +73,22 @@
                 {"id": 10100, "label": "sad"},
                 {"id": 10101, "label": "happy"}
               ]
+            },
+            "customfield_10300": {
+              "required": false,
+              "schema": {
+                "type": "array",
+                "items": "option",
+                "custom": "com.atlassian.jira.plugin.system.customfieldtypes:multiselect",
+                "customId": 10202
+              },
+              "name": "Feature",
+              "hasDefaultValue": false,
+              "operations": ["add", "set", "remove"],
+              "allowedValues": [
+                {"value": "Feature 1", "id": "10105"},
+                {"value": "Feature 2", "id": "10106"}
+              ]
             }
           }
         }
@@ -476,6 +492,14 @@ def get_client():
                 'label': 'Mood',
                 'default': '',
                 'choices': [('sad', 'sad'), ('happy', 'happy')],
+            }, {
+                'multiple': True,
+                'required': False,
+                'type': 'select',
+                'name': 'customfield_10300',
+                'label': 'Feature',
+                'default': '',
+                'choices': [('Feature 1', 'Feature 1'), ('Feature 2', 'Feature 2')],
             }]
 
     def test_get_create_issue_config_with_default_and_param(self):
@@ -636,6 +660,8 @@ def responder(request):
             body = json.loads(request.body)
             assert body['fields']['labels'] == ['fuzzy', 'bunnies']
             assert body['fields']['customfield_10200'] == {'value': 'sad'}
+            assert body['fields']['customfield_10300'] == [
+                {'value': 'Feature 1'}, {'value': 'Feature 2'}]
             return (200, {'content-type': 'application/json'}, '{"key":"APP-123"}')
 
         responses.add_callback(
@@ -651,6 +677,7 @@ def responder(request):
             'issuetype': '1',
             'project': '10000',
             'customfield_10200': 'sad',
+            'customfield_10300': ['Feature 1', 'Feature 2'],
             'labels': 'fuzzy , ,  bunnies'
         })
         assert result['key'] == 'APP-123'