How to delete a tag from a Jira ticket using Python?

I know how to add a tag to a Jira ticket in Python:

ticket.fields.labels.append("NEW_TAG")

But I can’t figure out how to remove one. I tried this but it didn’t work:

ticket.update(update={"labels": [{"remove": {"name": "OLD_TAG"}}]})

This method works for removing components, but not labels. I’ve looked through the docs and searched online but haven’t found a solution.

I need to update hundreds of tickets, so doing it manually isn’t an option. The bulk editor in the browser doesn’t work for me either.

Any ideas on how to remove a label from a Jira ticket using Python? Thanks!

I’ve encountered a similar issue before. The solution that worked for me was using the ‘set’ method to update the labels. Here’s the code snippet:

ticket.update(fields={‘labels’: set(ticket.fields.labels) - {‘OLD_TAG’}})

This approach effectively removes the specified tag without affecting other labels. It’s efficient for bulk updates as well. Just ensure you have the necessary permissions to modify tickets. Also, remember to test this on a single ticket before applying it to your entire set of tickets. Hope this helps solve your problem!

I’ve had to tackle this exact problem in a large-scale Jira cleanup project. What worked for me was using the ‘update’ method with a slightly different syntax:

ticket.update(fields={‘labels’: [label for label in ticket.fields.labels if label != ‘OLD_TAG’]})

This approach uses a list comprehension to create a new list of labels, excluding the one you want to remove. It’s efficient and works well for bulk updates.

One thing to keep in mind: make sure you’re using the latest version of the Jira Python library, as older versions might have inconsistencies in how they handle label updates.

Also, don’t forget to commit your changes after the update:

ticket.update()

This method has been reliable for me across different Jira instances and configurations. Good luck with your cleanup!

hey joec, have u tried using the remove() method? smth like this might work:

ticket.fields.labels.remove(‘OLD_TAG’)
ticket.update(fields={‘labels’: ticket.fields.labels})

not 100% sure but worth a shot. lmk if it helps!