MattParr / python-atws

Autotask Web Services python module
MIT License
32 stars 10 forks source link

Picklist reverse_lookup not working #53

Closed DylanWhite2 closed 5 years ago

DylanWhite2 commented 5 years ago

See code ran and traceback below.

at.picklist['Ticket']['Status'].reverse_lookup(5)
Traceback (most recent call last):
  File ".\test.py", line 16, in <module>
    at.picklist['Ticket']['Status'].reverse_lookup(5)
  File "C:\Users\Dwhite\AppData\Local\Programs\Python\Python37\lib\site-packages\atws\picklist.py", line 224, in reverse_lookup
    label = get_value_label(value, self._picklist, condition=condition)
  File "C:\Users\Dwhite\AppData\Local\Programs\Python\Python37\lib\site-packages\atws\picklist.py", line 60, in get_value_label
    item = find('Value', value, picklistvalues, condition=condition)
  File "C:\Users\Dwhite\AppData\Local\Programs\Python\Python37\lib\site-packages\atws\picklist.py", line 34, in find
    raise KeyError('label not found in index', index_label, index_name)
KeyError: ('label not found in index', 'Value', 5)
MattParr commented 5 years ago

Hi Dylan.

I think it would be odd that '5' isn't found as this should correspond to 'Complete' I wonder if you get the same result with a string:

at.picklist['Ticket']['Status'].reverse_lookup('5')
mtingers commented 4 years ago

I'm still having a problem with this issue in the latest version. As noted, using a string lookup works, but documentation indicates an integer will work. Example:

>>> # Does not work
>>> at.picklist['Ticket']['Status'].reverse_lookup(1)                                                                                                                  
>>> # This does work
>>> at.picklist['Ticket']['Status'].reverse_lookup('1')

The root of the problem surrounds the types that are returned from a Ticket query versus the pick list type. Example:

>>> type(at.picklist['Ticket']['Status']['New'])
<class 'suds.sax.text.Text'>
>>> type(ticket)
<class 'suds.sudsobject.Ticket'>
>>> type(ticket.Status)
<class 'int'>

I put in a temporary workaround for my codebase on reverse_lookup by casting "value" to a string, but this may not be ideal and they are actually integers (but seems to work for now):

    def reverse_lookup(self, value, condition=is_active):
        ''' take a field_name_id and return the label '''
        label = get_value_label(str(value), self._picklist, condition=condition)
        return label
MattParr commented 4 years ago

I'm okay with that.. and me a pull request.

On Wed, 4 Dec 2019, 9:29 AM Matthew Ingersoll, notifications@github.com wrote:

I'm still having a problem with this issue in the latest version. As noted, using a string lookup works, but documentation indicates an integer will work. Example:

Does not work

at.picklist['Ticket']['Status'].reverse_lookup(1)

This does work

at.picklist['Ticket']['Status'].reverse_lookup('1')

The root of the problem surrounds the types that are returned from a Ticket query versus the pick list type. Example:

type(at.picklist['Ticket']['Status']['New']) <class 'suds.sax.text.Text'>

type(ticket) <class 'suds.sudsobject.Ticket'> type(ticket.Status) <class 'int'>

I put in a temporary workaround for my codebase on reverse_lookup by casting "value" to a string, but this may not be ideal and they are actually integers (but seems to work for now):

def reverse_lookup(self, value, condition=is_active):
    ''' take a field_name_id and return the label '''
    label = get_value_label(str(value), self._picklist, condition=condition)
    return label

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/MattParr/python-atws/issues/53?email_source=notifications&email_token=ABIM745ZCUPOCPHCLWD66HDQW26T5A5CNFSM4GVIEREKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEF2WX5I#issuecomment-561343477, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABIM745RDCCOGL3EYLOUZZDQW26T5ANCNFSM4GVIEREA .