Update Issues with the Python API

How does Updating Issues with python Code work?

Im Using the Python Gitlab Library
https://python-gitlab.readthedocs.io/en/stable/gl_objects/issues.html
and the attributes i get from Gitlab Issues https://docs.gitlab.com/ee/api/issues.html

The Company im Working for, uses self managed Gitlab, were running on core version “13.2”.
We Automate much in the Issue section, like generated Issue when our internal support gets a request for a problem. To get some Statistics done we would like to automate the assignee stuff inside this section, but heres the Problem. we arent able to update issues with Python code.

first heres the Code.

def test():
closed_issues  = pro_ject.issues.list(state='closed', assigne_username='none')
for issue in closed_issues:
    issue.assignees = {
        "avatar_url": "https://secure.gravatar.com/avatar/e5d35b4ff36f7c0e81c54ba92e009f27?s=80&d$
        "state": "active",
        "username": "my-username",
        "id": 00,
        "name": "my Name"}
    issue.save()
    print(issue) #Debug Purpose

After Python reaches the line “issue.save()” it crashes and giving us this little piece of error message:

Traceback (most recent call last):
  File "__main__.py", line 21, in <module>
options.test()
  File "/**/**/**/**/options.py", line 77, in test
issue.save()
  File "/usr/local/lib/python3.7/dist-packages/gitlab/mixins.py", line 385, in save
server_data = self.manager.update(obj_id, updated_data, **kwargs)
  File "/usr/local/lib/python3.7/dist-packages/gitlab/exceptions.py", line 281, in wrapped_f
raise error(e.error_message, e.response_code, e.response_body) from e
gitlab.exceptions.GitlabUpdateError: 400: assignee_id, assignee_ids, confidential, created_at, description, discussion_locked, due_date, labels, add_labels, remove_labels, milestone_id, state_event, title are missing, at least one parameter must be provided

I tried to just assigne it with “assignee_iid=00” and “assignee_username=‘my-username’” but it wont work either. When i dont use the save() function, i see no errors in my output. and the issue seems like in the right format. Any explanation would help i guess.

Best Regards.

What’s the Python library you are using?

Im Using the Python Gitlab Library
https://python-gitlab.readthedocs.io/en/stable/gl_objects/issues.html
and the attributes i get from Gitlab Issues https://docs.gitlab.com/ee/api/issues.html

Reading here a possible cause is if you are using a http endpoint instead of a https endpoint - can you double-check your configuration, please?

Also, if you try to print the issue, does it have anything?

for issue in closed_issues:
    print(issue)
2 Likes

The print has all information i need. except that infromation about the assignement…

<class 'gitlab.v4.objects.ProjectIssue'> => {'id': 1468, 'iid': 37, 'project_id': 422, 'title': 'Test_label', 'description': 'label_issue', 'state': 'closed', 'created_at': '2020-06-30T08:35:47.636Z', 'updated_at': '2020-08-26T11:01:00.512Z', 'closed_at': '2020-06-30T09:53:36.558Z', 'closed_by': {'id': 98, 'name': '**** ****', 'username': '****', 'state': 'active', 'avatar_url': 'https://secure.gravatar.com/avatar/e5d35b4ff36f7c0e81c54ba92e009f27?s=80&d=identicon', 'web_url': 'https://intranet.lan.****-****.com/****'}, 'labels': [], 'milestone': None, 'assignees': [], 'author': {'id': 104, 'name': '***', 'username': '***', 'state': 'active', 'avatar_url': 'https://secure.gravatar.com/avatar/72d7dc018c42b3d29749405925a50b5f?s=80&d=identicon', 'web_url': 'https://intranet.lan.****-****.com/***'}, 'assignee': None, 'user_notes_count': 0, 'merge_requests_count': 0, 'upvotes': 0, 'downvotes': 0, 'due_date': '2020-05-01', 'confidential': False, 'discussion_locked': None, 'web_url': 'https://intranet.lan.****-****.com/****/test-project-issue_by_mail/-/issues/37', 'time_stats': {'time_estimate': 0, 'total_time_spent': 0, 'human_****e_es****ate': None, 'human_total_time_spent': None}, 'task_completion_status': {'count': 0, 'completed_count': 0}, 'has_tasks': False, '_links': {'self': 'https://intranet.lan.****-****.com/api/v4/projects/422/issues/37', 'notes': 'https://intranet.lan.****-****.com/api/v4/projects/422/issues/37/notes', 'award_emoji': 'https://intranet.lan.****-****.com/api/v4/projects/422/issues/37/award_emoji', 'project': 'https://intranet.lan.****-****.com/api/v4/projects/422'}, 'references': {'short': '#37', 'relative': '#37', 'full': '****/test-project-issue_by_mail#37'}, 'moved_to_id': None, 'subscribed': True}

it is a https endpoint.

I tried this description += ’ ’ thing and now the Issue has been updated. but still no assignement…

Hi,

1

I’m also experiencing this issue.

It seems there may be a bug in the python API that adds a 4s sleep in the update method. `time.sleep(4)` at end of `Resource.update`? · Issue #622 · pycontribs/jira · GitHub

Since this bug has been open for almost 2 years, I think it’s time for a fork!

get the great solution from python notes