from typing import Any


def safe_text(text: Any) -> str:
    """Process text of any type to ensure it can be saved in the DB."""
    # Ensure bytes get decoded, no matter what, to unicode.
    if isinstance(text, bytes):
        text = text.decode('UTF-8', errors='replace')
    elif not isinstance(text, str):
        text = str(text)
    # Replace null characters with nothing to prevent db errors.
    return text.replace('\x00', '')