devopshq / youtrack

YouTrack Python 3 Client Library
https://devopshq.github.io/youtrack/
MIT License
27 stars 14 forks source link

Unable to retrieve custom Enum bundles #9

Closed felipead closed 7 years ago

felipead commented 7 years ago

It's not possible to retrieve custom enum bundles. These methods from Connection class don't work:

connection.get_bundle('enum', 'bundle_id')
connection.get_enum_bundle('bundle_id')

They return empty objects. I've debugged these objects and I could see that their _data properties is an empty dictionary.

When issuing an HTTP request directly, as in:

GET /rest/admin/customfield/bundle/40-30-1470750250809 

This is the (anonymized) response I get:

<?xml version="1.0" ?>
<enumeration name="40-30-1470750250809">
    <value>A</value>
    <value>B</value>
    <value>C</value>
    <value description="The quick brown fox jumps over the lazy dog.">D</value>
    <value description="The quick brown fox jumps over the lazy dog.">E</value>
    <value description="The quick brown fox jumps over the lazy dog.">F</value>
    <value description="The quick brown fox jumps over the lazy dog.">G</value>
    <value description="The quick brown fox jumps over the lazy dog.">H</value>
    <value description="The quick brown fox jumps over the lazy dog.">Foo &amp; Bar</value>
    <value>I</value>
    <value>J</value>
    <value>K</value>
    <value>L</value>
    <value description="">M</value>
    <value description="The quick brown fox jumps over the lazy dog.">N</value>
    <value>O</value>
    <value description="The quick brown fox jumps over the lazy dog.">P</value>
    <value description="The quick brown fox jumps over the lazy dog.">Q</value>
    <value>R</value>
    <value description="The quick brown fox jumps over the lazy dog.">S</value>
</enumeration>

This is my debugging session:

ipdb> bundle = connection.get_enum_bundle('40-30-1470750250809')
ipdb> type(bundle)
<class 'youtrack.youtrack.EnumBundle'>
ipdb> bundle.to_xml()
*** TypeError: a bytes-like object is required, not 'str'
ipdb> bundle._data
{}
ipdb> str(bundle)
''
ipdb> bundle.values
[, , , , , , , , , , , , , , , , , , , ]
ipdb> len(bundle.values)
20
ipdb> bundle_value = bundle.values[0]
ipdb> type(bundle_value)
<class 'youtrack.youtrack.EnumField'>
ipdb> bundle_value._data
{}
ipdb> str(bundle_value)
''
ipdb> bundle_value.to_xml()
*** TypeError: a bytes-like object is required, not 'str'
allburov commented 7 years ago

Hello! Really, _data is empty in bundle and value objects.

But you can get all information about value from object.attirbutes, like this:

 bundle = connection.get_enum_bundle('40-30-1470750250809')
bundle_value = bundle.values[0]
print(bundle_value.element_name)
print(bundle_value.description)

I don't know why _data is empty. One underscore is weak "internal use" indicator. So, don't use it ;) It used on Issue and other classes.

What python version do you use? I get an error in bundle.to_xml() https://github.com/devopshq/youtrack/issues/10

allburov commented 7 years ago

@felipead Can we close this issue? I am working with to_xml in #10

felipead commented 7 years ago

@allburov Python 3.6.3

felipead commented 7 years ago

@allburov yes, you can close the issue. Thank you!

allburov commented 7 years ago

Thanks for the feedback! :)

felipead commented 7 years ago

I've finally found out the the code that produce the results I wanted:

    def teams(self) -> List[str]:
        bundle_id = self.__connection.get_custom_field('Team')['defaultBundle']
        return (i.name for i in self.__connection.get_enum_bundle(bundle_id).values)