microsoftgraph / msgraph-sdk-ruby

Microsoft Graph Ruby client library for v1 APIs
https://graph.microsoft.com
MIT License
99 stars 68 forks source link

Can't create Group "A value is required for property 'displayName' of resource 'Group'." #188

Open noah-stahl opened 4 months ago

noah-stahl commented 4 months ago

Hi, I'm trying to create a new group, I initialize a GraphServiceClient just like in the README

context = MicrosoftKiotaAuthenticationOAuth::ClientCredentialContext.new(
  TENANT_ID, CLIENT_ID, CLIENT_SECRET
)

authentication_provider = MicrosoftGraphCore::Authentication::OAuthAuthenticationProvider.new(
  context, nil, ['https://graph.microsoft.com/.default']
)

adapter = MicrosoftGraph::GraphRequestAdapter.new(authentication_provider)
@client = MicrosoftGraph::GraphServiceClient.new(adapter)

Then I try to build a Group object and POST it I pieced this code together by using this doc https://learn.microsoft.com/en-us/graph/api/group-post-groups?view=graph-rest-1.0 as well as another user's code from this issue https://github.com/microsoftgraph/msgraph-sdk-ruby/issues/163#issuecomment-1786640674

new_group = MicrosoftGraph::Models::Group.new.tap do |group|
  group.display_name = 'My new Group'
  group.mail_enabled = false
  group.mail_nickname = 'newgroup'
  group.security_enabled = true
  group.group_types = ['Unified']
end

@client.groups.post(new_group).resume

But I get an error back with the following message A value is required for property 'displayName' of resource 'Group'. What am I missing?

baywet commented 4 months ago

Thanks for using the Ruby SDK and for reaching out. For sanity, do you get the same result with ?

new_group = MicrosoftGraph::Models::Group.new()
new_group.display_name = 'My new Group'
new_group.mail_enabled = false
new_group.mail_nickname = 'newgroup'
new_group.security_enabled = true
new_group.group_types = ['Unified']
noah-stahl commented 4 months ago

Hi, thanks for the quick answer. I tried that and got the same result. This is what my group object looks like before I try to post it, so it seems to have all the necessary attributes

<MicrosoftGraph::Models::Group:0x0000ffff93f29ef8 @additional_data={}, @odata_type="#microsoft.graph.group", @display_name="My new Group", @mail_enabled=false, @mail_nickname="newgroup", @security_enabled=true, @group_types=["Unified"]>

Looking at the request that is being sent, it seems like the request body is missing

baywet commented 4 months ago

That's a very good call-out. We had a fix for this very issue a couple of days ago. Make sure your version of abstractions is up to date with latest. https://github.com/microsoft/kiota-abstractions-ruby/pull/33

noah-stahl commented 4 months ago

Thanks for the heads up, it seems I was on an older version. Unfortunately, I'm having some trouble getting all the dependencies to resolve correctly.

At first I tried simply specifying the version in my Gemfile

Gemfile

gem 'microsoft_graph', '~> 0.22.1'
gem 'microsoft_kiota_abstractions', '~> 0.14.4'

but the same issue persisted. I presume this is because the request is made by microsoft_kiota_faraday, which is still using microsoft_kiota_abstractions 0.12.0, as I could see in my Gemfile.lock

Gemfile.lock

microsoft_graph (0.22.1)
      microsoft_graph_core (~> 0.3.1)
    microsoft_graph_core (0.3.1)
      microsoft_kiota_abstractions (~> 0.14.0)
      microsoft_kiota_authentication_oauth (~> 0.8.0)
      microsoft_kiota_faraday (~> 0.12.0)
      microsoft_kiota_serialization_json (~> 0.9.0)
    microsoft_kiota_abstractions (0.14.4)
      iso8601 (~> 0.13.0)
      stduritemplate (~> 0.0.39)
    microsoft_kiota_authentication_oauth (0.8.0)
      microsoft_kiota_abstractions (~> 0.14.0)
      oauth2 (~> 2.0)
    microsoft_kiota_faraday (0.12.0)
      faraday (~> 2.7, >= 2.7.2)
      microsoft_kiota_abstractions (~> 0.14.0)
    microsoft_kiota_serialization_json (0.9.1)
      json (~> 2.6.3)
      microsoft_kiota_abstractions (~> 0.14.0)
      uuidtools (~> 2.2.0)

I tried to use the newest version of microsoft_kiota_faraday which is as of very recently 0.14.0, by specifying it in my Gemfile

Gemfile

gem 'microsoft_graph', '~> 0.22.1'
gem 'microsoft_kiota_abstractions', '~> 0.14.4'
gem 'microsoft_kiota_faraday', '~> 0.14.0'

But that seems to be impossible because of microsoft_graph and microsoft_graph_core depending on microsoft_kiota_faraday ~> 0.12.0, I get the following error

> bundle install
Fetching gem metadata from https://rubygems.org/........
Resolving dependencies...
Could not find compatible versions

Because microsoft_graph >= 0.20.0 depends on microsoft_graph_core ~> 0.3.1
  and microsoft_graph_core >= 0.3.1 depends on microsoft_kiota_faraday ~> 0.12.0,
  microsoft_graph >= 0.20.0 requires microsoft_kiota_faraday ~> 0.12.0.
So, because Gemfile depends on microsoft_graph ~> 0.22.1
  and Gemfile depends on microsoft_kiota_faraday ~> 0.14.0,
  version solving has failed.
baywet commented 4 months ago

Ok, let's unblock you with two pull requests. Can you first prepare a release of core by:

  1. Bumping the patch version https://github.com/microsoftgraph/msgraph-sdk-ruby-core/blob/main/lib%2Fmicrosoft_graph_core%2Fversion_information.rb
  2. Adding an entry to the changelog (today's date, changed)
  3. Triple checking all Kiota dependencies are up to date.

After that gets published, I'll ask you to do the same here.

baywet commented 4 months ago

Core release is out, please go ahead with the same for this repo. Please review the changes I've pushed to the changelog in the first pr and align with that.

baywet commented 4 months ago

0.22.2 was just released which should fix your issue. Closing. Thanks for the help getting the releases out! Don't hesitate if you need more help!

noah-stahl commented 4 months ago

Thanks for the help, I've updated to the 0.22.2 version and my Gemfile.lock looks like this now

microsoft_graph (0.22.2)
      microsoft_graph_core (~> 0.3.1)
    microsoft_graph_core (0.3.2)
      microsoft_kiota_abstractions (~> 0.14.0)
      microsoft_kiota_authentication_oauth (~> 0.8.0)
      microsoft_kiota_faraday (>= 0.12, < 0.15)
      microsoft_kiota_serialization_json (~> 0.9.0)
    microsoft_kiota_abstractions (0.14.4)
      iso8601 (~> 0.13.0)
      stduritemplate (~> 0.0.39)
    microsoft_kiota_authentication_oauth (0.8.0)
      microsoft_kiota_abstractions (~> 0.14.0)
      oauth2 (~> 2.0)
    microsoft_kiota_faraday (0.14.0)
      faraday (~> 2.7, >= 2.7.2)
      microsoft_kiota_abstractions (~> 0.14.0)
    microsoft_kiota_serialization_json (0.9.1)
      json (~> 2.6.3)
      microsoft_kiota_abstractions (~> 0.14.0)
      uuidtools (~> 2.2.0)

So microsoft_kiota_faraday is now on the 0.14.0 version, but unfortunately the problem of the blank request body is still unchanged

baywet commented 4 months ago

Thanks for your patience on the matter. I was out due to sick leave (my schedule is still impacted at this point).

I believe this issue is simply due to a dependencies mis-alignment.

I'm not sure how dependencies are managed in ruby (are they deduplicated like in dotnet/javascript/...? if so, what rationale is being applied? or are they isolated and multiple versions can be in the application context?) But getting clarity on the behaviour would be helpful.

What would be interesting to do to rule this out would be to clone all the repositories, and link all packages locally

  1. all kiota packages should link to local version of abstractions.
  2. core should link to local versions of kiota dependencies.
  3. this gem should link to 1 & 2.
  4. the application should link to the 3 (and if needed 1 & 2)

Can you try this approach locally and report on the result please? If that solves the issue, we'll bump all versions and dependencies gradually on all repository to ensure people get only the latest aligned versions with the fix.

Another test worth performing would be to try get the serialized value (from the parse node) and see if the representation is what is expected before it's set on the request information's content. (see [this as an example]9https://github.com/microsoft/kiota-abstractions-ruby/blob/7367a156276923eddd22e52335adbba88b1bf71e/lib/microsoft_kiota_abstractions/request_information.rb#L96) you can just copy some of the code, pass the group object and checkout what will be in the resulting content, make sure you instantiate the client first to register the serialization providers)

I hope this helps. Let me know if you have further questions.