RedHatQE / pylero

Python wrapper for the Polarion WSDL API
https://redhatqe.github.io/pylero/
MIT License
37 stars 25 forks source link

Unsupported WSDL class #154

Closed AlthausKonstantin closed 1 year ago

AlthausKonstantin commented 1 year ago

Dear All,

I am running in an issue with some of my companies Polarion projects.

Here is a MWE

# %% make my token available
from keyring import get_password
my_token = get_password("polarion", "personal-token")

# %% connect to polarion
from os import environ
environ["POLARION_PROJECT"] = "WHB2019"
environ["POLARION_REPO"] = "https://server.of.my.company/polarion/repo"
environ["POLARION_URL"] = "https://server.of.my.company/polarion"
environ["POLARION_TOKEN"] = my_token

# %% The Problem
from pylero.work_item import Risk  # we have this workitem type
id = 'WHB-52683' # this is an existing workitem
some_risk = Risk(work_item_id=id) # KeyError: 'duration'

I have done some digging...

  1. The error occurs in the method get_custom_fields in this linebecause globals() does not contain the key 'duration':
    cls._cls_suds_map[local_name]["cls"] = globals()[parse_type[1]]
  2. The key 'duration' turns up here because our workitem type 'Risk' has the custom field type 'Version' which has the type 'ns106:duration':
    cfts = Risk.get_defined_custom_field_types('WHB2019',Risk._wi_type) 
    version_type = cfts[14] # for me the version type is at 14
    print(version_type.name) # prints "Version"
    print(version_type.type) # prints "ns106:duration"

    As we get a type beginning with 'ns', pylero assumes that this type is in the global namespace. (that's what I gleaned from that code-comment) For other Polarion WSDL classes, such as the suds 'Text' from pylero.text, this is also the case.

  3. Checking further with the suds client, I also see that the Polarion project in question has this class. This

    print(Risk.session.tracker_client._suds_client)

    produces the following output (here only a shortened version):

    Suds ( https://fedorahosted.org/suds/ )  version: 1.1.2
    
    Service ( TrackerWebServiceService ) tns="http://ws.polarion.com/TrackerWebService"
       Prefixes (5)
        ...
       Ports (1):
          (TrackerWebService)
             Methods (188):
                ...
             Types (74):
                ...
                ns4:duration
                ...

I also looked at the tracker client WSDL resources from Polarion (here) and saw that the duration type is a really simple type wich is essentially equivalent to the base type 'string'. Here is the type definition of the WSDL class:

<simpleType name="duration">
<restriction base="xsd:string"/>
</simpleType>

... but here I need your input

Thank you for your help!

leelavg commented 1 year ago

Is there some other workaround?

  • I'm afraid that I don't know this

AlthausKonstantin commented 1 year ago

Thank you! No worries, for now I will try to talk to our repo admins maybe we can change the type on the server side. I will let you know if this fixes my problem :)

leelavg commented 1 year ago

Ack, in general we might need to look into how suds map simpleType with backing base types and hack into it if possible 🤔

AlthausKonstantin commented 1 year ago

I was able to fix the problem by avoiding the simple types :)

Ack, in general we might need to look into how suds map simpleType with backing base types and hack into it if possible

Agreed. In my superficial research I got the impression that suds does not support simple types fully :(