I am developing an idempotency mechanism for creating issue on jira. My method is to use a custom_field when creating an issue and use JQL to search for that specific custom field value to check if an issue exists.
I write this code:
def create_issue_with_custom_field(
jira_client: JIRA,
project_key: str,
summary: str,
description: str,
issue_type: str,
custom_field_id: str=”customfield_12345”,
operation_id: str,
) -> object:
"""
Create a Jira issue and set a custom field during creation.
"""
fields = {
"project": {"key": project_key},
"summary": summary,
"description": description,
"issuetype": {"name": issue_type},
custom_field_id: operation_id,
}
issue = jira_client.create_issue(fields=fields)
return issue
The above code trigger this error:
RuntimeError: Failed to create issue for operation_id=create_issue:tenant-42:event-123456: JiraError HTTP 400 url: https://xxxxxxxx.atlassian.net/rest/api/2/issue
text: Field ‘customfield_12345’ cannot be set. It is not on the appropriate screen, or unknown.