Returns a dictionary containing the set of data from primary and secondary
    where values in primary will always be returned if present, and values in
    secondary will only be returned if not present in primary, or if the value
    in primary is `None`.

    Sample input Data::

        primary = [
            {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'name_key': 'xyz'},
            {'a': None, 'b': 12, 'c': 13, 'd': 14, 'name_key': 'qrs'},
            {'a': None, 'b': 12, 'c': 13, 'd': 14, 'name_key': 'def'},
        ]
        secondary = [
            {'a': 31, 'e': 33, 'name_key': 'xyz'},
            {'a': 11, 'e': 23, 'name_key': 'qrs'},
            {'a': 1, 'e': 3, 'name_key': 'ghi'},
        ]

    Returns:
        dict: Dictionary of key value pairs from obj1 and obj2::

            {
                'xyz': {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 33, 'name_key': 'xyz'},
                'qrs': {'a': 11, 'b': 12, 'c': 13, d: 14, e: 23, 'name_key': 'qrs'},
                'def': {'a': None, 'b': 12, 'c': 13, 'd': 14, 'name_key': 'def'},
                'ghi': {'a': 1, 'e': 3, 'name_key': 'ghi'}
            }

def merge_lvm_data(primary, secondary, name_key):
    """
    Returns a dictionary containing the set of data from primary and secondary
    where values in primary will always be returned if present, and values in
    secondary will only be returned if not present in primary, or if the value
    in primary is `None`.

    Sample input Data::

        primary = [
            {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'name_key': 'xyz'},
            {'a': None, 'b': 12, 'c': 13, 'd': 14, 'name_key': 'qrs'},
            {'a': None, 'b': 12, 'c': 13, 'd': 14, 'name_key': 'def'},
        ]
        secondary = [
            {'a': 31, 'e': 33, 'name_key': 'xyz'},
            {'a': 11, 'e': 23, 'name_key': 'qrs'},
            {'a': 1, 'e': 3, 'name_key': 'ghi'},
        ]

    Returns:
        dict: Dictionary of key value pairs from obj1 and obj2::

            {
                'xyz': {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 33, 'name_key': 'xyz'},
                'qrs': {'a': 11, 'b': 12, 'c': 13, d: 14, e: 23, 'name_key': 'qrs'},
                'def': {'a': None, 'b': 12, 'c': 13, 'd': 14, 'name_key': 'def'},
                'ghi': {'a': 1, 'e': 3, 'name_key': 'ghi'}
            }

    """
    pri_data = to_name_key_dict(primary, name_key)
    # Prime results with secondary data, to be updated with primary data
    combined_data = to_name_key_dict(secondary, name_key)
    for name in pri_data:
        if name not in combined_data:
            # Data only in primary
            combined_data[name] = pri_data[name]
        else:
            # Data in both primary and secondary, pick primary if better or no secondary
            combined_data[name].update(dict(
                (k, v) for k, v in pri_data[name].items()
                if v is not None or k not in combined_data[name]
            ))

    return set_defaults(combined_data)