def get_valid_messages(log, expiry):
    """
    Return only the messages that haven't expired.
    """

    valid = []
    for message in log:
        try:
            timestamp = int(message.get('timestamp', 0))
            if timestamp > expiry:
                valid.append(message)
        except ValueError:
            continue

    return valid