Write_file hook. Error when uploading a file to third party. OSError: File does not exist

So I have configured a hook on hooks.py , write_file = "app.hooks.attachment" where the method is like this

def attachment(doc):
   url = upload_to_digitalocean()
   return {"file_name": doc.file_name, "file_url": url}

This is based on source code . But when after uploading the file and returning the dictionary I get OSError: File does not exist

This seems to happens on validate_file_on_disk() method.

Question is; If I want to upload certain file to remote, how can I bypass this check?

UPDATE: Seems like I have to update file_url

def attachment(doc):
   url = upload_to_digitalocean()
   doc.file_url = url
   return {"file_name": doc.file_name, "file_url": url}