teachers_pet
teachers_pet copied to clipboard
Error on create_student_teams
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.
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
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!
@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.
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:in
new'
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:in
block 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:in
create_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:in
create_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:in
invoke_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:in
start'
from ./bin/teachers_pet:4:in `
@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>
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.
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.