Skip to content
This repository has been archived by the owner on Feb 5, 2018. It is now read-only.

Error on create_student_teams #110

Open
michaelfahy opened this issue Mar 17, 2015 · 7 comments
Open

Error on create_student_teams #110

michaelfahy opened this issue Mar 17, 2015 · 7 comments

Comments

@michaelfahy
Copy link

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
Copy link
Author

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!

@tarebyte
Copy link
Member

@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!

@afeld
Copy link
Contributor

afeld commented Mar 19, 2015

@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 #88.

@michaelfahy
Copy link
Author

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 `

'

@aronwc
Copy link
Contributor

aronwc commented Aug 27, 2015

@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
Copy link
Contributor

aronwc commented Aug 27, 2015

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.

rahuldave added a commit to cs109/teachers_pet that referenced this issue Sep 4, 2015
rahuldave added a commit to cs109/teachers_pet that referenced this issue Sep 4, 2015
@erikmd
Copy link

erikmd commented Mar 14, 2016

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.

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

No branches or pull requests

5 participants