Closed goiri closed 2 months ago
I think this should result in None
being passed into the function and the code can deal with it accordingly. I believe that's the behavior for the other languages.
As I mentioned at the end, I think the behavior overall is fine but there are two things that would help:
Pushing the None to the Python code might be a little weird, given that if I specify a non-existing blob directly it doesn't end up in that. I would totally support if both situations end up passing a None.
Yes, I think both cases should pass None. We want to let user code decide what to do because an error isn’t always the desired result. Here’s an example of another language (C# script) where it receives null if the file doesn’t exist and the function handles it by creating the file with a blob output: https://github.com/anthonychu/slack-user-change-alerts/blob/master/src/SlackUserChangeAlerts.Function/CheckUserListChanges/run.csx#L13
Thanks @anthonychu, that would work for us. I can check if what I received is None and return my own 404 with a detailed message.
Waiting for deployment
FYI for anyone down the line running into this issue, the error described (exception ending in "data_type = data.type") can be worked around in python by removing types from the parameters. ie:
def main(req: func.HttpRequest, notebooksindexin: bytes) -> func.HttpResponse:
can be changed to the below to workaround the issue.
def main(req, notebooksindexin):
Hi guys, I am debugging my azure function locally and I keep on getting the same error presented above, But the thing is my blob actually exists so I have no clue why i'm getting this error ! I have tried what @WilliamShimizu suggested And it kind of helps, since it changed my error to the following : the JSON object must be str, bytes or bytearray, not NoneType
I tracked this error down to see from where it originated, and appearently one of my variables (oldSession) is equal to None, but the thing is this parameter is specified in bindings as an input, and it's corresponding blob actually exists and is not empty, so i trully don't understand why oldSession is equal to None:
"type": "blob",
"name": "oldSession",
"path": "azure-webjobs-secrets/camerarequest/session.txt",
"connection": "AzureWebJobsStorage",
"direction": "in"
Note : A colleague of mine uses the same code (since we both pulled from github) and we use the same azure storage and all, but it works fine for him, which basically means that there is no problem with the code neither with the blob (session.txt) !! Do you guys have any suggestions ? I would appreciate any kind of help
When will this land? I'd rather get a None
blob and handle it in my Python code than the current behavior of seeing error logs with 'NoneType' object has no attribute 'type'
.
Just realized something, how will we know the name of the blob we attempted to fetch if all we get passed is None
?
The fix for returning None for non-existent blobs has been merged. Please make sure you're using an azure-functions
version >= 1.3.1 to get this fix.
Alternatively, using SDK type bindings with blob results in throwing a ResourceNotFoundError: 'The specified blob does not exist.'
, if that works better in a specific scenario.
If you're using an HTTP trigger, you can grab the blob name passed into the function like so:
@app.route(route="hello/{name}")
@app.blob_input(arg_name="inputBlob", path="container/{name}", connection="AzureWebJobsStorage")
def http_trigger(req: func.HttpRequest, inputBlob: func.InputStream) -> func.HttpResponse:
blob_name = req.route_params.get('name')
logging.info(f"Blob name: {blob_name}")
When a function is triggered through HTTP with a named parameter (e.g., userparam) and we have a blob binding with such parameter in the name and it does not exist, the runtime throws:
The definition of the function can be something like:
The key here is to pass "userparam" such that "file-{userparam}.json" does not exist.
This eventually fails and returns a 500. However, I don't think this is the most graceful behavior. My proposal would be to:
I am running the azure functions runtime locally and executing queries but I think that's not relevant other than I should be able to test a possible solution fast.