Bug 1549085

Summary: internal server error ActiveRecord::AssociationTypeMismatch when editing miq_groups
Product: Red Hat CloudForms Management Engine Reporter: Martin Kourim <mkourim>
Component: APIAssignee: Brandon Dunne <bdunne>
Status: CLOSED NEXTRELEASE QA Contact: Martin Kourim <mkourim>
Severity: medium Docs Contact:
Priority: low    
Version: 5.8.0CC: cpelland, gtanzill, jprause, mkourim, obarenbo, simaishi, yrudman
Target Milestone: GAKeywords: ZStream
Target Release: 5.8.5   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard: api:rest
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-09-07 17:52:27 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: CFME Core Target Upstream Version:
Embargoed:

Description Martin Kourim 2018-02-26 11:23:31 UTC
Description of problem:
When editing the "miq_groups" the request fails with:
{
	"error": {
		"kind": "internal_server_error",
		"message": "MiqGroup(#105333660) expected, got Hash(#11727220)",
		"klass": "ActiveRecord::AssociationTypeMismatch"
	}
}


Version-Release number of selected component (if applicable):
5.8.3.4
The same request works on 5.9.0.22.


How reproducible:
100%


Steps to Reproduce:
1. create a user
2. POST /api/users/:id
{
	"action": "edit",
	"resource": {
		"miq_groups": [
			{"href": "https://addr/api/groups/13"},
			{"href": "https://addr/api/groups/6"}
		]
	}
}
Response:
{
	"error": {
		"kind": "internal_server_error",
		"message": "MiqGroup(#105333660) expected, got Hash(#11727220)",
		"klass": "ActiveRecord::AssociationTypeMismatch"
	}
}

Comment 2 Jillian Tullo 2018-02-26 18:29:19 UTC
The reason for this issue is that on 5.8, `miq_groups` was not supported, it was added later on for the G release. In this version, only a single group is allowed, which sets the `miq_groups` to that partciular group.

In 5.8, the following editing of groups was allowed:
POST /api/users/:id
{
	"action": "edit",
	"resource": {
            "group": { "description": "group_description" }
	}
}

Also supported are id and href for a group.

However, I will fix to return an appropriate error message, unless this feature is requested in 5.8. Please let me know what approach to take.

Thank you!

Comment 3 Martin Kourim 2018-02-27 08:27:08 UTC
Thanks for clarification Jillian, I don't know of any request to support this feature in 5.8 (I just tried if it works there), appropriate error message seems good enough to me.
Also severity can be decreased.
Thank you!