msgraph-sdk-ruby icon indicating copy to clipboard operation
msgraph-sdk-ruby copied to clipboard

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

Open noah-stahl opened this issue 1 year ago • 9 comments

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?

noah-stahl avatar Feb 15 '24 16:02 noah-stahl

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']

baywet avatar Feb 15 '24 17:02 baywet

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

noah-stahl avatar Feb 16 '24 09:02 noah-stahl

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

baywet avatar Feb 16 '24 12:02 baywet

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.

noah-stahl avatar Feb 16 '24 12:02 noah-stahl

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 avatar Feb 16 '24 13:02 baywet

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 avatar Feb 16 '24 14:02 baywet

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!

baywet avatar Feb 16 '24 14:02 baywet

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

noah-stahl avatar Feb 16 '24 15:02 noah-stahl

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.

  • microsoft_kiota_abstractions should be 0.14.4
  • microsoft_kiota_faraday should be 0.15.0

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.

baywet avatar Feb 22 '24 15:02 baywet

@baywet It doesn't seem like this issue is fixed no matter the version conflicts and unreleased code.

I just did:

gem "microsoft_graph", github: "microsoftgraph/msgraph-sdk-ruby"
gem "microsoft_graph_core", github: "microsoftgraph/msgraph-sdk-ruby-core"
gem "microsoft_kiota_faraday", github: "microsoft/kiota-http-ruby"
gem 'microsoft_kiota_abstractions' , github: 'microsoft/kiota-abstractions-ruby'

to get the latest code released on main for all of the related libraries and I am still encountering an empty body.

As of now this whole SDK is useless for write operations AFAIK.

itay-grudev avatar Aug 15 '24 13:08 itay-grudev

/reopen

itay-grudev avatar Aug 15 '24 13:08 itay-grudev

NVM! Don't reopen it. This is all caused by https://github.com/microsoft/kiota-serialization-json-ruby/issues/20. But that issue is still preventing POST requests and has been there for a while now.

So the SDK is still useless for a lot of write operations.

itay-grudev avatar Aug 15 '24 21:08 itay-grudev