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

Query parameter does not work properly when retrieving users #31

Closed
m-moris opened this issue Nov 29, 2021 · 14 comments · Fixed by #41
Closed

Query parameter does not work properly when retrieving users #31

m-moris opened this issue Nov 29, 2021 · 14 comments · Fixed by #41
Assignees
Labels
bug Something isn't working fixed

Comments

@m-moris
Copy link

m-moris commented Nov 29, 2021

Hi

I have created a sample program to retrieve a user, but the query parameter does not seem to be working correctly.
When I debug it, it seems that the query parameter is not set correctly, is it still a limitation?

The following sample query for the CreatedDateTime property to be included in the response, but returns NULL.

func getUser(client *msgraphsdk.GraphServiceClient, id string) {

	options := &usersitem.UserRequestBuilderGetOptions{
		Q: &usersitem.UserRequestBuilderGetQueryParameters{
			Select_escaped: []string{"createdDateTime"},
		},
	}
	result, err := client.UsersById(id).Get(options)
	if err != nil {
		fmt.Printf("Error get user : %v\n", err)
		return
	}

	fmt.Printf("result.GetDisplayName(): %v\n",result.GetDisplayName())
	fmt.Printf("result.GetCreatedDateTime(): %v\n", result.GetCreatedDateTime())
}

Thanks.

@baywet baywet self-assigned this Nov 29, 2021
@baywet baywet added Needs author feedback question Further information is requested labels Nov 29, 2021
@baywet
Copy link
Member

baywet commented Nov 29, 2021

hi @m-moris
Thanks for reaching out and for trying the Go SDK.

Can you confirm you're on latest for all the dependencies by running go get -u please?

Can you also test whether it's specific to that parameter (select) by trying to use a filter query parameter for the same request please and see if it works?
(I suspect this is caused by the _escaped suffix)

Thanks!

@m-moris
Copy link
Author

m-moris commented Nov 29, 2021

Hi

The results of "go get" will have to wait a bit.

I tried followning sample using client.Users().Get(options) method. This is an example of a filter to get only hotmail accounts, but it does not work correctly.

	f := "endsWith(mail,'@hotmail.com')"
	options := &u.UsersRequestBuilderGetOptions{
		Q: &u.UsersRequestBuilderGetQueryParameters{
			Filter:         &f,
		},
	}

	result, err := client.Users().Get(options)
	if err != nil {
		fmt.Printf("Error get user : %v\n", err)
		return
	}

I debugged it, following line converts the data from "requestInfo" to "nethttp.Request". However, the "getRequestFromRequestInformation" function does not seem to be doing any filtering.

https://github.com/microsoft/kiota/blob/main/http/go/nethttp/nethttp_request_adapter.go#L95

The following is the value of the request after conversion. Normally, the filter value would be set to "rawQuery".

*net/url.URL {Scheme: "https", Opaque: "", User: *net/url.Userinfo nil, Host: "graph.microsoft.com", Path: "/v1.0/users", RawPath: "", ForceQuery: false, RawQuery: "", Fragment: "", RawFragment: ""}

Thanks

@baywet
Copy link
Member

baywet commented Nov 29, 2021

Thanks for the additional information.
The behaviour you're describing sounds a lot like we solved in #17 and #13. Let's wait for the go get -u to complete and see how that impacts the results, I believe your application is a bit behind on dependencies at this point.

@m-moris
Copy link
Author

m-moris commented Nov 30, 2021

Hi

The results of "go get -u" are attached. This will take a long time, so this is the result in the middle of execution.
Is this information enough for you?

$ go get -u
go: downloading github.com/microsoft/kiota/authentication/go/azure v0.0.0-20211129093841-858bd540489b
go: downloading github.com/microsoftgraph/msgraph-sdk-go v0.3.0
go: downloading github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.12.0
go: downloading github.com/microsoft/kiota v0.0.14
go: downloading github.com/Azure/azure-sdk-for-go/sdk/azcore v0.20.0
go: downloading github.com/Azure/azure-sdk-for-go v59.4.0+incompatible
go: downloading github.com/microsoft/kiota/abstractions/go v0.0.0-20211112084539-17ac73ffdc7c
go: downloading github.com/microsoft/kiota/serialization/go/json v0.0.0-20211112084539-17ac73ffdc7c
go: downloading github.com/microsoftgraph/msgraph-sdk-go-core v0.0.2
go: downloading github.com/microsoft/kiota/serialization/go/json v0.0.0-20211129093841-858bd540489b
go: downloading github.com/microsoft/kiota/abstractions/go v0.0.0-20211129093841-858bd540489b
go: downloading github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.1
go: downloading github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.2
go: downloading github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4
go: downloading github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8
go: downloading golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897
go: downloading golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871
go: downloading github.com/google/uuid v1.3.0
go: downloading github.com/microsoft/kiota/http/go/nethttp v0.0.0-20211112084539-17ac73ffdc7c
go: downloading github.com/yosida95/uritemplate/v3 v3.0.1
go: downloading github.com/microsoft/kiota/http/go/nethttp v0.0.0-20211129093841-858bd540489b
go: downloading github.com/yosida95/uritemplate v2.0.0+incompatible
go: downloading golang.org/x/net v0.0.0-20211029224645-99673261e6eb
go: downloading golang.org/x/net v0.0.0-20211123203042-d83791d6bcd9

@m-moris
Copy link
Author

m-moris commented Nov 30, 2021

I updated library to the latest and the filter was working. However, the "Select_escaped" still did not seem to be working.

	options := &u.UsersRequestBuilderGetOptions{
		Q: &u.UsersRequestBuilderGetQueryParameters{
			Filter:         &f,
			Select_escaped: []string{"createdDateTime"},
		},
	}

image

@baywet baywet added bug Something isn't working and removed question Further information is requested Needs author feedback labels Nov 30, 2021
@baywet
Copy link
Member

baywet commented Nov 30, 2021

Thanks for the additional information here.
I logged a bug in the generator to go solve that issue. As I suspected, the SDK is sending a request with &select_escaped=foo to the service, and the service ignores it.
I'll revert here to provide an update once this is fixed.

@baywet
Copy link
Member

baywet commented Nov 30, 2021

Update: I've put together a PR in the generator, once it gets merged, I'll be able to put a PR together here and in the beta SDK which should address the issue.

@baywet
Copy link
Member

baywet commented Dec 1, 2021

update, unfortunately the previous PR introduced a regression, I've put another PR to fix that regression here

@baywet
Copy link
Member

baywet commented Dec 2, 2021

Hi @m-moris
The pull request that addresses the issue just got merged.
Please run go get -u on you project to pull the latest version of the SDK and try again.
Also the property name will have changed from Select_escaped to Select.
Thanks for your patience!

@m-moris
Copy link
Author

m-moris commented Dec 6, 2021

@baywet

Thank you for your support.

Select_escape property has been changed to Select property , Such as following sample. But unfortunately, the select query still does not works correctly.

	f := "startsWith(mail,'bob')"
	options := &u.UsersRequestBuilderGetOptions{
		Q: &u.UsersRequestBuilderGetQueryParameters{
			Filter: &f,
			Select: []string{"createdDateTime"},
		},
	}

	resultx, err := client.Users().Get(options)
	if err != nil {
		fmt.Printf("Error geuser : %v\n", err)
		return
	}

I have debugged deeply, and there seems to be a bug in the following points.

select is not included in this map, so it does not seem to be recognized as a query correctly.

https://github.com/microsoft/kiota/blob/main/abstractions/go/request_information.go#L46

Thanks.

@baywet
Copy link
Member

baywet commented Dec 6, 2021

Hi @m-moris
Thanks for the follow up on this one, and sorry I missed this additional aspect in the original fix.
The parameter name matching for the url template is case sensitive, and the Go conventions "force" the use of a uppercase character for the first letter of a field if you want to make it public.
In lots of cases, including in #44 opened by @Marco98 earlier today, this led to casing mismatch and the parameter being ignored by the template.

I've put together microsoft/kiota#917 which addresses that aspect, once it gets merged running go get -u should address the issue.
Thank you both!

@baywet baywet added the fixed label Dec 6, 2021
@baywet
Copy link
Member

baywet commented Dec 7, 2021

The pull request was merged.

@m-moris
Copy link
Author

m-moris commented Dec 7, 2021

Hi @baywet

Thank you for your support. Select queries are now working!

@baywet
Copy link
Member

baywet commented Dec 7, 2021

Thanks for confirming, closing.

@baywet baywet closed this as completed Dec 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants