Skip to content

[BUG] MatchedAddress from_dict not working #7

@ryanhaarmann

Description

@ryanhaarmann

I'm not sure if this library is still being maintained, but the MatchedAddress.from_dict assumes it's getting {'results': 'matchedAddresses': {'matchedAddress': {}}} but in Location it's already parsing the list of matchedAddresses, passing on the dictionary of the matched address.

I was able to patch this locally and confirm it's working.

@classmethod
def new_from_dict(cls, as_dict):
    """Create an instance of the geographic entity from its
           :class:`dict <python:dict>` representation.

           :param as_dict: The :class:`dict <python:dict>` representation of the geographic
             entity.
           :type as_dict: :class:`dict <python:dict>`

           :returns: An instance of the geographic entity.
           :rtype: :class:`GeographicEntity`

           """
    as_dict = validators.dict(as_dict, allow_empty=False)

    address = as_dict.get('matchedAddress', None)
    longitude = as_dict.get('coordinates', {}).get('x', None)
    latitude = as_dict.get('coordinates', {}).get('y', None)
    tigerline_side = as_dict.get('tigerLine', {}) \
        .get('side', None)
    tigerline_id = as_dict.get('tigerLine', {}) \
        .get('tigerLineId', None)
    pre_type = as_dict.get('addressComponents', {}) \
        .get('preType', None)
    suffix_type = as_dict.get('addressComponents', {}) \
        .get('suffixType', None)
    pre_qualifier = as_dict.get('addressComponents', {}) \
        .get('preQualifier', None)
    suffix_qualifier = as_dict.get('addressComponents', {}) \
        .get('suffixQualifier', None)
    pre_direction = as_dict.get('addressComponents', {}) \
        .get('preDirection', None)
    suffix_direction = as_dict.get('addressComponents', {}) \
        .get('suffixDirection', None)
    from_address = as_dict.get('addressComponents', {}) \
        .get('fromAddress', None)
    to_address = as_dict.get('addressComponents', {}) \
        .get('toAddress', None)
    street = as_dict.get('addressComponents', {}) \
        .get('streetName', None)
    city = as_dict.get('addressComponents', {}) \
        .get('city', None)
    state = as_dict.get('addressComponents', {}) \
        .get('state', None)
    zip_code = as_dict.get('addressComponents', {}) \
        .get('zip', None)

    return cls(**{
        'tigerline_id': tigerline_id,
        'tigerline_side': tigerline_side,
        'longitude': longitude,
        'latitude': latitude, # also found this misspelled 
        'pre_type': pre_type,
        'suffix_type': suffix_type,
        'pre_qualifier': pre_qualifier,
        'suffix_qualifier': suffix_qualifier,
        'pre_direction': pre_direction,
        'suffix_direction': suffix_direction,
        'from_address': from_address,
        'to_address': to_address,
        'street': street,
        'city': city,
        'state': state,
        'zip_code': zip_code,
        'address': address
    })

MatchedAddress.from_dict = new_from_dict

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions