jesper-raemaekers / python-polarion

A Python package to access the Polarion WSDL API.
MIT License
56 stars 35 forks source link

How to create a workitem from scratch? #56

Closed ergorion closed 2 years ago

ergorion commented 2 years ago

The documentation does not give an example for creating a new workitem in Polarion from scratch. from polarion import workitem client1 = polarion.Polarion(url, user, password) project= client1.getProject('project') workitem.Workitem(client1, project) will raise an exception: Exception: No id, uri, polarion workitem or new workitem type specified!

Defining a new workitem type, e.g. workitem.Workitem(client1, project, new_workitem_type='changerequest') also raises an exception: Fault: javax.transaction.RollbackException: Workflow initialization failed for Work Item 'prefix-73487': The required field 'title' of Work Item 'prefix-73487' is empty. So, this goes to the server, polarion tries to create a work item, but fails due to the missing title. But looking at the source, I see now way how to hand over a title (or any other field value) for creating a work item.

I then tried to play around with workitem.Workitem(client1, project, polarion_workitem = work_item_properties) But this lead nowhere, because the work_item_properties seemingly need to be of type zeep.objects.WorkItem. So, maybe this could be used for copying one workitem to a new one?

Thanx a lot in advance, Axel

jesper-raemaekers commented 2 years ago

I cannot believe that was not in the docs....

You're looking for a method in the project class, which has no docstring. I've quickly added it, but you're looking for this example:


    new_task = project.createWorkitem('changerequest')
ergorion commented 2 years ago

thanx for the fast response. However, this results in the same exception as creating the Workitem object:

Fault: javax.transaction.RollbackException: Workflow initialization failed for Work Item 'prefix-73488': The required field 'title' of Work Item 'prefix-73488' is empty.

It seems I need a way to hand over the mandatory fields for the creation of a work item...

ergorion commented 2 years ago

I looked around a bit more. Your suggestion to use project.createWorkitem('changerequest') is a call to Workitem(self.polarion, self, new_workitem_type=workitem_type) which explains the same exception :-) Fault: javax.transaction.RollbackException: Workflow initialization failed for Work Item 'prefix-73488': The required field 'title' of Work Item 'prefix-73488' is empty.

Digging into the Workitem. init, I have played around with handing over the title when creating the new WorkItemType (workitem.py, line 57): elif new_workitem_type is not None: self._polarion_item = self._polarion.WorkItemType( type=self._polarion.EnumOptionIdType(id=new_workitem_type), title='TEST')

And this worked. Somehow. Because the server side exception changed to: Fault: javax.transaction.RollbackException: Workflow initialization failed for Work Item 'prefix-73492': The required field 'description' of Work Item 'prefix-73492' is empty.

And this is where I'm stuck now. No matter how I try to define the description, e.g. description = 'test' or description = {'type': 'text/plain', 'content': 'Test', 'contentLossy': False} I keep getting rejected by the server, the last line triggering: Fault: javax.transaction.RollbackException: Workflow initialization failed for Work Item 'prefix-73492': The required field 'description' of Work Item 'prefix-73492' is empty.

Any ideas?

jesper-raemaekers commented 2 years ago

I now changed my Polarion project config to require title and description and I was able to reproduce that exception.

I'll update when I have something working.

jesper-raemaekers commented 2 years ago

Please have a look at the commit I just made. Copy those changes and try again with the following snippet:

client = Polarion('http://localhost/polarion', '', '')
project = client.getProject('')
new_task = project.createWorkitem('task', new_workitem_fields={'title': 'hallo!', 'description': client.TextType(
            content='A description', type='text/html', contentLossy=False)})

This allows you to pass a dictionary with fields that can be filled in at creation. I opted for a dict since in polarion you can require any field to be filled in. Let me know if this works for you.

ergorion commented 2 years ago

Thanx for the fast response, again. I applied your changes, but still: wi = project.createWorkitem('changerequest', new_workitem_fields={'title': 'This is the title', 'description': client1.TextType(content='a desription for this ChangeRequest', type='text/html', contentLossy=False)})

I get: Fault: javax.transaction.RollbackException: Workflow initialization failed for Work Item 'prefix-73507': The required field 'description' of Work Item 'prefix-73507' is empty.

ergorion commented 2 years ago

interesting observation:

jesper-raemaekers commented 2 years ago

That last bit makes sense if your task does not require the title or description. https://github.com/jesper-raemaekers/python-polarion/commit/26348598cb4a70ea847f6fcd6db0392866e0c1af#diff-a771326458e8cf9c5b71132767719ea6ed39634967af3bcbac9f0a659d94b40eR64 this line will prevent that. But to me, it should always be possible to add more fields if the user wants that. So that will be changing.

I will retry later with creating a change request. Usually i default to task as that is shorter :)

jesper-raemaekers commented 2 years ago

I was also able to create a changerequest. Can you access your polarion project configuration? If you can, can you look at 'work item > workflow' to see if there is anything special for your change request?

This is how it looks for me: image This is the default config with added required fields of title and description. Or maybe a custom field that is selected as required field?

ergorion commented 2 years ago

I got the server configuration for the required fields, looks slightly different than yours:

image

jesper-raemaekers commented 2 years ago

Is it also ticket as initial? I will copy those settings, but it feels like it may not be a difference.

ergorion commented 2 years ago

Is it also ticket as initial?

I'm not sure I understand your question. I had requested a screenshot of the change request configuration, if that's what you are asking...

jesper-raemaekers commented 2 years ago

I tried to copy those settings in your screenshot. I was still able to create it. It doesn't look like something to do with version, but for completeness. What is your python version and can you post your installed packages (pip list)?

Debugging wise it would be interesting to see what the state of the _polarion_item is at this point https://github.com/jesper-raemaekers/python-polarion/commit/b0ab45cbac58cf9674ec87c8c337fd37c812942e#diff-a771326458e8cf9c5b71132767719ea6ed39634967af3bcbac9f0a659d94b40eL74 while creating that change request.

Other than that, I'm not sure how to proceed. Perhaps a Teams (or equivalent) session may help. If that is interesting to your we can discuss that. (I'm happy to sign an NDA if needed, but it should be manageable without showing sensitive data)

ergorion commented 2 years ago

Finally, I have been able to setup a breakpoint in workitem.py. I Have to admit that the _polarion_item looks good: self._polarion_item { 'approvals': None, 'assignee': None, 'attachments': None, 'author': None, 'categories': None, 'comments': None, 'created': None, 'description': { 'type': 'text/html', 'content': 'a desription for this ChangeRequest', 'contentLossy': False }, 'dueDate': None, 'externallyLinkedWorkItems': None, 'hyperlinks': None, 'id': None, 'initialEstimate': None, 'linkedOslcResources': None, 'linkedRevisions': None, 'linkedRevisionsDerived': None, 'linkedWorkItems': None, 'linkedWorkItemsDerived': None, 'location': None, 'moduleURI': None, 'outlineNumber': None, 'plannedEnd': None, 'plannedInURIs': None, 'plannedStart': None, 'planningConstraints': None, 'previousStatus': None, 'priority': None, 'project': { [.... details about project removed but they also look ok....] }, 'remainingEstimate': None, 'resolution': None, 'resolvedOn': None, 'severity': None, 'status': None, 'timePoint': None, 'timeSpent': None, 'title': 'This is the title', 'type': { 'id': 'changerequest' }, 'updated': None, 'workRecords': None, 'customFields': None, 'uri': None, 'unresolvable': None }

This is the required_features: { 'actionId': -1, 'actionName': 'Initialization', 'cleanedFeatures': { 'item': [ 'signaturesWorkflow' ] }, 'nativeActionId': 'init', 'requiredFeatures': { 'item': [ 'title', 'description' ] }, 'suggestedFeatures': None, 'targetStatus': { 'id': 'draft' }, 'unavailabilityMessage': None }

ergorion commented 2 years ago

Now that we are confident that our side is working, I will raise a ticket in our help desk...

jesper-raemaekers commented 2 years ago

Thanks for the feedback. I'm curious to know if will be fixed in the end and please also provide the feedback if the issues ends up being in this package.

For now I am satisfied that the code should work, so after making some tests I will integrate this new feature.

ergorion commented 2 years ago

this is interesting. when I create a task, like: task = project.createWorkitem('task', new_workitem_fields={'title': 'This is the title', 'description': client1.TextType(content='a desription for this task', type='text/html', contentLossy=False)}) the task is created with the correct title, however, the field description remains empty. But a) I have made sure to apply your latest patch and b) I can see the description transferred in the xml debug output:

text/html a desription for this task false Now, when I try this for a changerequest, the server complains about the missing description. Which could make sense, a) as the description is also a required field in the case of a change request b) assuming that we send it over but the server does not really receive the information. Funny enough, when I do an update on the field description, it works in both cases (task as well as change request), e.g.: task.description = client1.TextType(content='a desription for this task', type='text/html', contentLossy=False) task.save() so to summarize: - I can create a task, but not a change request. - the server does not properly receive/recognize/decode the field description on create, but on update Can you make any sense out of this? Axel
jesper-raemaekers commented 2 years ago

You have sparked a thought. Try changing the self.TextType in _getTypes in polarion.py to

self.TextType = self.getTypeFromService('Tracker', 'ns1:Text')

Technically it uses the wrong type now, although i presumed the type 'text' was the same over all different services.

ergorion commented 2 years ago

I tried it out -- the result remains the same:

But we could be on the right track. When you create a task on your server with the description, does the description field get populated? What other options do we have to set this field? E.g. if I tried a simple, plain text string as a hard coded value for starters?

ergorion commented 2 years ago

When I retrieve a workitem from the server, I would assume the types and namespaces to be set correctly. This is the result for a getWorkitem for a change request:

text/html TEST_DESCRIPTION false with the following type namespace declarations: Does this help? Axel
jesper-raemaekers commented 2 years ago

But we could be on the right track. When you create a task on your server with the description, does the description field get populated? What other options do we have to set this field? E.g. if I tried a simple, plain text string as a hard coded value for starters?

I have another two options:

# one
existing_item = project.getWorkitem('PYTH-512')
new_item = project.createWorkitem('task', new_workitem_fields={'title': 'new title!', 'description': existing_item.description})
# two
other_new_item = project.createWorkitem('task', new_workitem_fields={'title': 'new title!', 'description': {'type':'text/html', 'contentLossy':False, 'content':'hallo!'}})

The first creates a task with the description from another workitem. The seconds constructs it via a dictionary.

The names all look good in that snippet from you.

Also what version polarion are you using? I'm on: Polarion® 21 R2 Build: 3.21.2.20210920-1545-21_R2-be900ca2 This information is in the bottom left if you open the settings menu.

ergorion commented 2 years ago

both attemps create a task, but the description remains empty. Really strange.

The version used is: Polarion® ALM™ 21 R1 Build: 3.21.1.20210615-1059-21_R1_P1-3aa597ca

jesper-raemaekers commented 2 years ago

Just an update that I have not found anything new to try. I also looked in the polarion log files, but it seems the only output is the exception returned via the API.

ergorion commented 2 years ago

I Just received an update from our internal service desk: they changed the way they create change requests. And now it works. Thanx for your support.