Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support json as a dataType for queueTrigger #4207

Open
TylerLeonhardt opened this issue Mar 19, 2019 · 7 comments
Open

Support json as a dataType for queueTrigger #4207

TylerLeonhardt opened this issue Mar 19, 2019 · 7 comments
Assignees

Comments

@TylerLeonhardt
Copy link
Member

Repro steps

  1. Have a queue trigger
  2. Insert a json string into the queue as the message data: {"hello":"World"}

Expected behavior

Function receives the json as a json object so it can be properly turned into a hashtable for PowerShell Function users

Actual behavior

Function receives the json as a string and it gets passed in as a string.

Known workarounds

param($QueueItem)

$parsedData = $QueueItem | ConvertFrom-Json

Related information

  • Programming language used - powershell
  • Bindings used - queueTrigger
@mhoeger
Copy link
Contributor

mhoeger commented Mar 29, 2019

@TylerLeonhardt - I think this should be behavior controlled by the language worker instead of the host? Ex: https://github.com/Azure/azure-functions-nodejs-worker/blob/b678aea76bfcba3ae082558d67e07745e29d5176/src/Converters.ts#L43

@pragnagopa
Copy link
Member

@TylerLeonhardt - As @mhoeger mentioned, host sends trigger input data as string/json

https://github.com/Azure/azure-functions-language-worker-protobuf/blob/2e9cf4b3ac3864e3f5db07dffefa751d38baa368/src/proto/FunctionRpc.proto#L284

Language worker needs to control how it is presented to the function code on invocation.

Closing this as for now. Please reopen if you still think we need to address this.

@TylerLeonhardt
Copy link
Member Author

TylerLeonhardt commented Apr 4, 2019

Sorry for the delay! Not sure how I missed this.

@mhoeger I see from the snippet that the node worker treats string/json as the same and attempts to parse it regardless (even if the TypedData is a string). Thanks for that! I can replicate that in the PowerShell worker... but it seems a bit confusing from a language worker's perspective.

My understanding would be that the host would use the TypedData as json if the data were json and string if it wasn't. We do this today in the powershell worker.

If the expectation is that the worker should try to parse TypedData.string as json, then is there any particular reason for TypedData.json over just sending everything through TypedData.string?

@pragnagopa
Copy link
Member

Host should set typedData.Json if the input data is a json string.

else if (value is JObject jobj)
{
typedData.Json = jobj.ToString();
}

Reopening this issue to investigate.

@pragnagopa pragnagopa reopened this Apr 5, 2019
@pragnagopa pragnagopa self-assigned this Apr 5, 2019
@pragnagopa pragnagopa added this to the Triaged milestone Apr 5, 2019
@TylerLeonhardt
Copy link
Member Author

Thanks @pragnagopa! We have implemented what the node worker does (thanks again for that, @mhoeger!) in Azure/azure-functions-powershell-worker#186

@daxian-dbw
Copy link

daxian-dbw commented May 5, 2019

A related issue: Azure/azure-functions-powershell-worker#205

@pragnagopa when fixing this issue, please be noted that for the RpcHttp.RawBody field, it should be kept as typedData.String even if it's a valid JSON string.

@fabiocav fabiocav removed this from the Triaged milestone Jan 23, 2024
@PowershellNinja
Copy link

I disagree with the OP in general as I personally find forced parsing of string values undesireable.

Regardless of that though, as it is implemented at the moment, it generates a "System.Management.Automation.OrderedHashtable", which from a PowerShell perspective seems wrong - the builtin ConvertFrom-Json Cmdlet creates a "System.Management.Automation.PSCustomObject" if used to parse a JSON string with one object in it.
Examples:

PS C:\> '{"action":"a","option":"b"}' | ConvertFrom-Json

action option
------ ------
a      b
PS C:\> '{"action":"a","option":"b"}' | ConvertFrom-Json | Get-Member

   TypeName: System.Management.Automation.PSCustomObject

Name        MemberType   Definition
----        ----------   ----------
Equals      Method       bool Equals(System.Object obj)
GetHashCode Method       int GetHashCode()
GetType     Method       type GetType()
ToString    Method       string ToString()
action      NoteProperty string action=a
option      NoteProperty string option=b

So, if the trigger absolutely needs to parse an input JSON string, it should in my opinion mirror PowerShell's normal behavior and create a PSCustomObject, not convert into a Hashtable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants