Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to retrieve custom Enum bundles #9

Closed
felipead opened this issue Oct 31, 2017 · 6 comments
Closed

Unable to retrieve custom Enum bundles #9

felipead opened this issue Oct 31, 2017 · 6 comments
Assignees
Labels

Comments

@felipead
Copy link

felipead commented Oct 31, 2017

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'
@felipead felipead changed the title Enum bundles are not working Unable to retrieve custom Enum bundles Oct 31, 2017
@allburov
Copy link
Member

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() #10

@allburov
Copy link
Member

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

@felipead
Copy link
Author

@allburov Python 3.6.3

@felipead
Copy link
Author

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

@allburov
Copy link
Member

Thanks for the feedback! :)

@felipead
Copy link
Author

felipead commented Nov 16, 2017

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants