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

Google Classroom Turn In API bad request error #1979

Open
mattszeto opened this issue May 17, 2023 · 27 comments
Open

Google Classroom Turn In API bad request error #1979

mattszeto opened this issue May 17, 2023 · 27 comments
Assignees
Labels
external This issue is blocked on a bug with the actual product. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@mattszeto
Copy link

mattszeto commented May 17, 2023

Environment details

  • Programming language: Go
  • OS: Mac OS
  • Language runtime version: 1.19
  • Package version: google.golang.org/api/classroom/v1 , google.golang.org/api v0.87.0

Steps to reproduce

running this code snippet (given valid course id, coursework id and submission id...):

_,err = service.Courses.CourseWork.StudentSubmissions.TurnIn(submission.CourseID, submission.courseWorkID, submission.ID, &classroom.TurnInStudentSubmissionRequest{}).Context(ctx).Do()

gives this error:

googleapi: Error 400: Invalid JSON payload received. Unknown name "": Root element must be a message.
Details:
[
  {
    "@type": "type.googleapis.com/google.rpc.BadRequest",
    "fieldViolations": [
      {
        "description": "Invalid JSON payload received. Unknown name \"\": Root element must be a message."
      }
    ]
  }
]

I read the docs and found no information on what TurnInStudentSubmissionRequest is. It seem its only purpose is to provide an empty request body. So, my assumption is to just include an empty struct, but i am left with a 400 bad request error stating above issue.

Am I writing this call incorrectly?

@mattszeto mattszeto added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels May 17, 2023
@codyoss codyoss assigned quartzmo and unassigned codyoss May 17, 2023
@JohnsoNeal2013
Copy link

JohnsoNeal2013 commented May 17, 2023 via email

@quartzmo
Copy link
Member

The Go client docs for TurnInStudentSubmissionRequest indeed show it as an empty struct. I will continue investigating.

@codyoss
Copy link
Member

codyoss commented May 19, 2023

Instead of &classroom.TurnInStudentSubmissionRequest{} can you try setting that param to nil.

@mattszeto
Copy link
Author

Instead of &classroom.TurnInStudentSubmissionRequest{} can you try setting that param to nil.

I had initially tried that too, same result. I can double check, if that's what worked for you, but i do remember the same error happening and then trying the empty struct.

@mattszeto
Copy link
Author

@codyoss setting the param to nil produces the same error

@noahdietz
Copy link
Contributor

I'm on rotation now so I've looked into this. I have strong reason to believe that this is either an issue in the backend (not expecting a body when it should be) or a misconfiguration of their HTTP settings (those that ultimately serve the API and are used to generate this client library). I will open a bug internally and follow up here with y'all.

@noahdietz
Copy link
Contributor

@mattszeto I don't have a good way to test this API, can you reproduce the issue with curl and/or the API Explorer on the API's rest documentation?

Screenshot 2023-05-22 at 10 09 03 AM

If so, please share your findings! This will go a long way in helping us nail down the root cause.

@noahdietz
Copy link
Contributor

As a sanity check, I verified that the JSON encoder used to prepare the request body reader produces a {} as expected. It does:

package main

import (
	"fmt"
	"io"

	classroom "google.golang.org/api/classroom/v1"
	"google.golang.org/api/googleapi"
)

func main() {
	req := &classroom.TurnInStudentSubmissionRequest{}
	r, err := googleapi.WithoutDataWrapper.JSONReader(req)
	if err != nil {
		fmt.Println(err)
		return
	}
	d, err := io.ReadAll(r)
	if err != nil {
		fmt.Println(err)
		return
	}
	fmt.Printf("marshaled: %s\n", string(d))
}

@mattszeto
Copy link
Author

mattszeto commented May 22, 2023

@mattszeto I don't have a good way to test this API, can you reproduce the issue with curl and/or the API Explorer on the API's rest documentation?

I was not able to reproduce the issue in the API's rest documentation or this curl:

curl --location --request POST 'https://classroom.googleapis.com/v1/courses/611043409401/courseWork/611047629407/studentSubmissions/Cg4IgKXMqOQREN_Em6rkEQ:turnIn' \
--header 'Authorization: Bearer {{token}}'

they were both successful.

As a sanity check, I verified that the JSON encoder used to prepare the request body reader produces a {} as expected.

Yes, that was my first concern, but it checked out. So I am stumped.

@noahdietz
Copy link
Contributor

Thanks so much for doing that. One more favor, @mattszeto:

or this curl:

Could you try that but include an empty message body e.g. "{}"?

@mattszeto
Copy link
Author

Could you try that but include an empty message body e.g. "{}"?

adding an empty message body produced the same 200 success response:

{}

@noahdietz
Copy link
Contributor

Thanks a bunch @mattszeto

@codyoss if this isn't reproducible via cURL, there may be an issue with the client itself...hm

@noahdietz
Copy link
Contributor

I already filed a bug internally, through which I hope to get an integration test setup to repro & debug with.

@noahdietz
Copy link
Contributor

@mattszeto and @JohnsoNeal2013 was this a new behavior that has impacted some existing application? If so, when did it start happening?

@noahdietz
Copy link
Contributor

if this isn't reproducible via cURL, there may be an issue with the client itself...hm

Also, Cody tested almost identical code for another API that had an empty request message and it worked just fine. That indicates the issue should be in the service.

@mattszeto
Copy link
Author

mattszeto commented May 23, 2023

@mattszeto and @JohnsoNeal2013 was this a new behavior that has impacted some existing application? If so, when did it start happening?

new implementation of this function for an existing application, which has a bunch of other google classroom functions that are working perfectly fine.

@noahdietz
Copy link
Contributor

An engineer from the service team has triaged it, but will need some time to get to it. They'll dig deeper next week.

@codyoss
Copy link
Member

codyoss commented May 24, 2023

In the meantime you can fallback to using our transport package to create an authenticated client and manually create the request.(note you will need to pass the correct scopes) I believe if you send a nil to body on https://pkg.go.dev/net/http#NewRequest it should work. https://pkg.go.dev/google.golang.org/api@v0.124.0/transport/http#NewClient

@mattszeto
Copy link
Author

Thanks guys! has there been any update on this issue?

@noahdietz
Copy link
Contributor

Sorry, not yet, but I will bump the bug!

@noahdietz
Copy link
Contributor

Got confirmation of the bug, but still not scheduled to be fixed. @mattszeto have you tried the authenticated client that Cody suggested? If so, has it worked for you?

@mattszeto
Copy link
Author

Have not tried that method yet. Hoping to get this issue solved so i don't have to 😅

@mattszeto
Copy link
Author

@noahdietz any updates on this being work on soon?

@codyoss codyoss added the external This issue is blocked on a bug with the actual product. label Jul 31, 2023
@codyoss
Copy link
Member

codyoss commented Jul 31, 2023

No updates to share as of right now. For now I would suggest the workaround above for the time being: #1979 (comment)

@quartzmo quartzmo assigned noahdietz and unassigned quartzmo Aug 2, 2023
@mattszeto
Copy link
Author

Wanted to reach out again and see if there are any updates to this issue. I've made an attempt to fork and fix the issue myself, so if there is any insight to where the issue could be would be helpful.

if this isn't reproducible via cURL, there may be an issue with the client itself...hm

Also, Cody tested almost identical code for another API that had an empty request message and it worked just fine. That indicates the issue should be in the service.

it was mentioned here by @noahdietz that it's an issue with the service, is this the case?

@noahdietz
Copy link
Contributor

No update, the team is too busy to address it atm, I'm sorry. It's a matter of prioritization, not denial of an issue.

@noahdietz
Copy link
Contributor

One other debugging thing that might be worth doing is ensuring (via debugger or printf) that {} is actually sent when you provide the non-nil body &classroom.TurnInStudentSubmissionRequest{}. My test in #1979 (comment) should've verified that an empty struct should still produce {} but who knows....

@googleapis googleapis deleted a comment from Adawntoremember Mar 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external This issue is blocked on a bug with the actual product. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

5 participants