def METHOD_NAME(candidate):
    """
    Fetch and update the candidates' metadata from Wikidata.
    This function needs to be duplicated here, as versioned models used in
    migrations do not include custom methods.
    """
    candidate.last_metadata_request_at = timezone.now()
    resp = requests.get(
        WIKIDATA_API_BASE_URL,
        params={
            "action": "wbgetentities",
            "languages": "fr|en",
            "sitefilter": "frwiki",
            "ids": candidate.uid.split(":")[1],
            "format": "json",
        },
    )
    resp.raise_for_status()
    wd_item = resp.json()["entities"][candidate.uid.split(":")[1]]
    wd_labels = wd_item["labels"]
    wd_claims = wd_item["claims"]
    def get_property_value(property_id):
        return wd_claims[property_id][0]["mainsnak"]["datavalue"]["value"]
    metadata = {
        "name": wd_labels.get("fr", {}).get("value")
        or wd_labels.get("en", {}).get("value"),
        "frwiki_title": wd_item["sitelinks"].get("frwiki", {}).get("title"),
    }
    # Image (P18)
    if "P18" in wd_claims:
        image_file = get_property_value("P18")
        encoded_filename = quote(image_file, safe="")
        image_url = (
            "https://commons.wikimedia.org/wiki"
            + f"/Special:Redirect/file/{encoded_filename}?width=800"
        )
        metadata["image_url"] = image_url
    # Official website (P856)
    if "P856" in wd_claims:
        metadata["website_url"] = get_property_value("P856")
    # Youtube channel ID (P2397)
    if "P2397" in wd_claims:
        metadata["youtube_channel_id"] = get_property_value("P2397")
    # Twitter username (P2002)
    if "P2002" in wd_claims:
        metadata["twitter_username"] = get_property_value("P2002")
    candidate.metadata = metadata
    candidate.metadata_timestamp = timezone.now()