ewsterrenburg / python-otrs

Pythonic interface to OTRS SOAP API
GNU General Public License v3.0
47 stars 27 forks source link

TicketCreate() assumes falsely that a ticket number looks like a number (an int) #46

Open vincentborghi opened 3 years ago

vincentborghi commented 3 years ago

My OTRS instance has a specific ticket number generator, so ticket numbers are not made of digits only (an example of ticket number in my system is "210315-VT1203" ). Apparently (and if I understand), non-numeric ticket numbers cause TicketCreate() to fail when it generates its return infos.

For example I have a ticket number like "210315-VT1203" and I obtained this error (although the ticket is created as expected): Traceback (most recent call last): File "./testpyotrs.py", line 45, in createtest() File "./testpyotrs.py", line 37, in createtest client.tc.TicketCreate(t, a,) # [df1, df2], [att1]) File "/usr/local/lib/python3.6/site-packages/otrs/client.py", line 109, in add_auth return func(self, *args, **kwargs) File "/usr/local/lib/python3.6/site-packages/otrs/ticket/operations.py", line 46, in call infos = {extract_tagname(i): int(i.text) for i in elements} File "/usr/local/lib/python3.6/site-packages/otrs/ticket/operations.py", line 46, in infos = {extract_tagname(i): int(i.text) for i in elements} ValueError: invalid literal for int() with base 10: '210315-VT1203'

Thanks

vincentborghi commented 3 years ago

Same issue is found when calling TicketUpdate(). ...and posibly other places where int(i.text) is applied to the ticket number...

ewsterrenburg commented 2 years ago

Agreed that the assumption of a ticket number that strictly consists of numbers should be removed. Will think about how to implement this (pull request is also welcome...)

vincentborghi commented 2 years ago

As a workaround, I have modified my python-otrs/otrs/ticket/operations.py as follows (just a quick hack that probably could be even simpler, shown below as a diff). The statement that hurts is: infos = {extract_tagname(i): int(i.text) for i in elements}

It appears in the "class TicketCreate" and in the "class TicketUpdate" definitions, so I applied the change the change to both places.


$ diff  python-otrs/otrs/ticket/operations.py.ori  python-otrs/otrs/ticket/operations.py
46c46,55
<         infos = {extract_tagname(i): int(i.text) for i in elements}
---
> #VBorghi 2021-03-17 patch to circumvent problem as we have ticket numbers containing non-digits
> #        infos = {extract_tagname(i): int(i.text) for i in elements}
>         infos = {}
>         for i in elements:
>             tagname = extract_tagname(i)
>             if tagname == 'TicketID':
>                 infos[tagname] = int(i.text)
>             elif tagname == 'TicketNumber':
>                 infos[tagname] = i.text   
> # End of patch
49a59
> 
170c180,189
<         infos = {extract_tagname(i): int(i.text) for i in elements}
---
> #VBorghi 2021-03-17 patch to circumvent problem as we have ticket numbers containing non-digits
> #        infos = {extract_tagname(i): int(i.text) for i in elements}
>         infos = {}
>         for i in elements:
>             tagname = extract_tagname(i)
>             if tagname == 'TicketID':
>                 infos[tagname] = int(i.text)
>             elif tagname == 'TicketNumber':
>                 infos[tagname] = i.text   
> # End of patch
171a191
>