teachers_pet icon indicating copy to clipboard operation
teachers_pet copied to clipboard

Error on create_student_teams

Open michaelfahy opened this issue 9 years ago • 7 comments

create_student_teams reports the error: json/common.rb:155:in `initialize': can't convert Sawyer::Resource to String (Sawyer::Resource#to_str gives NilClass) (TypeError) It successfully creates a team for the first student on the list but does not continue.

michaelfahy avatar Mar 17 '15 14:03 michaelfahy

Looks like this issue has been addressed in the closed issue "create_student_teams fails due to GitHub API change" but id still does not work!

michaelfahy avatar Mar 17 '15 17:03 michaelfahy

@michaelfahy

I can take a look at this later tonight, can you give the full error and possibly the snippet of your file that failed?

Thanks!

tarebyte avatar Mar 17 '15 18:03 tarebyte

@michaelfahy What version of teachers_pet do you have? You can run gem list -d teachers_pet to find out, then gem update teachers_pet to get the latest (0.3.5). Let us know if that works!

For reference, the issue referred to above is https://github.com/education/teachers_pet/issues/88.

afeld avatar Mar 19 '15 05:03 afeld

I am using teachers_pet 0.3.5.
My students file is a list of student github IDs. They already belong to a team named "students" in the organization. The create_student_teams commands authenticates to GitHub, reads the ids from the students file and successfully creates a team for the first student on the list but then displays this error and stops: /usr/local/rvm/gems/ruby-2.2.0/gems/json-1.8.2/lib/json/common.rb:155:in initialize': can't convert Sawyer::Resource to String (Sawyer::Resource#to_str gives NilClass) (TypeError) from /usr/local/rvm/gems/ruby-2.2.0/gems/json-1.8.2/lib/json/common.rb:155:innew' from /usr/local/rvm/gems/ruby-2.2.0/gems/json-1.8.2/lib/json/common.rb:155:in parse' from /home/michael/teachers_pet/lib/teachers_pet/actions/create_student_teams.rb:24:inblock in create_student_teams' from /home/michael/teachers_pet/lib/teachers_pet/actions/create_student_teams.rb:9:in each' from /home/michael/teachers_pet/lib/teachers_pet/actions/create_student_teams.rb:9:increate_student_teams' from /home/michael/teachers_pet/lib/teachers_pet/actions/create_student_teams.rb:33:in run' from /home/michael/teachers_pet/lib/teachers_pet/commands/create_student_teams.rb:10:increate_student_teams' from /usr/local/rvm/gems/ruby-2.2.0/gems/thor-0.19.1/lib/thor/command.rb:27:in run' from /usr/local/rvm/gems/ruby-2.2.0/gems/thor-0.19.1/lib/thor/invocation.rb:126:ininvoke_command' from /usr/local/rvm/gems/ruby-2.2.0/gems/thor-0.19.1/lib/thor.rb:359:in dispatch' from /usr/local/rvm/gems/ruby-2.2.0/gems/thor-0.19.1/lib/thor/base.rb:440:instart' from ./bin/teachers_pet:4:in `

'

michaelfahy avatar Mar 22 '15 18:03 michaelfahy

@michaelfahy any luck with this? I have the same problem.

It looks like the create_student_teams method tries to parse the result of client.create_team as a JSON object, but it returns something like this instead: <Sawyer::Resource:0x007f7f65374777>

aronwc avatar Aug 27 '15 16:08 aronwc

BTW, here is my workaround

--- a/lib/teachers_pet/actions/create_student_teams.rb
+++ b/lib/teachers_pet/actions/create_student_teams.rb
@@ -21,8 +21,9 @@ module TeachersPet
           if team
             puts "Team @#{org_login}/#{team_name} already exists."
           else
-            team = JSON.parse(self.client.create_team(org_login, team_name))
-            team.symbolize_keys!
+            res = self.client.create_team(org_login, team_name)
+            teams_by_name = self.client.existing_teams_by_name(org_login)
+            team = teams_by_name[team_name]
           end
           self.client.add_users_to_team(org_login, team, usernames)
         end

It makes extra calls to the GH API to get the new team ids, since they doesn't seem to be returned by the create_team call.

aronwc avatar Aug 27 '15 16:08 aronwc

Dear maintainers of teachers_pet, I was also faced with this issue yesterday, and @aronwc 's workaround worked like a charm. Could this fix be directly integrated in master? or should I open a PR? Best regards.

erikmd avatar Mar 14 '16 21:03 erikmd