community
cancel
Showing results for 
Search instead for 
Did you mean: 

Alteryx designer Discussions

Find answers, ask questions, and share expertise about Alteryx Designer.
Upgrade Alteryx Designer in 10 Steps

Debating whether or not to upgrade to the latest version of Alteryx Designer?

LEARN MORE

Python Tool - Bug with FixedDecimal(38,0) fields

Meteoroid

There is a bug in the python tool when the incoming data stream has a FixedDecmial field with 0 precision.  This bug only happens when you use the yxdb input type instead of the sqlite db.

 

Error:

 

Error: Tool #324: Traceback (most recent call last):
  File "C:\Users\\AppData\Local\Temp\18bb402002ae978202d137573811ca63\338\workbook.py", line 34, in <module>
    metadata = Alteryx.readMetadata("#1")
  File "C:\Users\\AppData\Local\Alteryx\bin\Miniconda3\PythonTool_Venv\lib\site-packages\ayx\export.py", line 80, in readMetadata
    return __CachedData__(debug=debug).readMetadata(incoming_connection_name, **kwargs)
  File "C:\Users\\AppData\Local\Alteryx\bin\Miniconda3\PythonTool_Venv\lib\site-packages\ayx\CachedData.py", line 597, in readMetadata
    field_type_str, context=filetype
  File "C:\Users\\AppData\Local\Alteryx\bin\Miniconda3\PythonTool_Venv\lib\site-packages\ayx\DatastreamUtils.py", line 647, in parseFieldTypeAndLengthStr
    self.__isValidFieldTypeLength(field_type, field_length, context=context)
  File "C:\Users\\AppData\Local\Alteryx\bin\Miniconda3\PythonTool_Venv\lib\site-packages\ayx\DatastreamUtils.py", line 824, in __isValidFieldTypeLength
    ).format(field_length_tuple, field_type_str, reasons)
ValueError: Field length tuple ((40,)) for specified field type (Fixed Decimal). Expected tuple length: [{'context': 'yxdb', 'expected_length': 2}]

 

 

If you are experiencing this error you can apply the following MonkeyPatch.  You will want to make sure this is in the first cell of your jupyter notebook.

 

 

from ayx.DatastreamUtils import MetadataTools
from re import findall
def getLengthOnly(self, field_type_and_length, error_if_invalid=False):
    # input must be a string, otherwise throw error
    if not isinstance(field_type_and_length, str):
        raise TypeError(
            "Invalid field type/length string: {}".format(
                convertObjToStr(field_type_and_length)
            )
        )
    # parse field length tuple from string
    field_length_str_list = findall(r"\b\d+", field_type_and_length)
    
    # Monkey patch for missing tuple value
    if 'fixeddecimal' in field_type_and_length and len(field_length_str_list) == 1:
        field_length_str_list.append('0')
    
    field_length_tuple = tuple(
        map(lambda length: int(length), field_length_str_list)
    )
    # if invalid tuple, throw an error
    try:
        self._MetadataTools__isValidFieldLengthTuple(field_length_tuple, error_if_invalid=True)
    except:
        print(
            "Invalid field length parsed out of from: {}".format(
                field_type_and_length
            )
        )
        raise
    # return the tuple representing the field length/precision
    return field_length_tuple

MetadataTools._MetadataTools__getLengthOnly = getLengthOnly

 

 

I hope this helps anyone else stuck with this error.

 

Ryan

Labels