Bug #22043
Unable to create location with organization_ids: [1] - Organizations is invalid
Status:
Closed
Priority:
Normal
Assignee:
Category:
Organizations and Locations
Target version:
Description
During creation of a location, if it is assigned organizations which are invalid the creation fails as the location attempts to validate the associated organization. (This also happens the other way around). This is due to has_and_belongs_to_many defaulting to validating the associated records as well.
Cloned from https://bugzilla.redhat.com/show_bug.cgi?id=1514915
Description of problem:
- curl -sku admin:changeme -d '{"location": {"name": "foo6", "organization_ids": [1]}}' -H 'Content-Type: application/json' https://$(hostname)/api/v2/locations
{
"error": {"id":null,"errors":{"organizations":["is invalid"]},"full_messages":["Organizations is invalid"]}
}
- specifying other (existing) organization id(s) works as expected
Actual results:
Organizations is invalid
Expected results:
Location created and assigned to Default Organization
Associated revisions
History
#1
Updated by The Foreman Bot over 4 years ago
- Assignee set to Tomer Brisker
- Status changed from New to Ready For Testing
- Pull request https://github.com/theforeman/foreman/pull/5104 added
#2
Updated by Marek Hulán over 4 years ago
- Legacy Backlogs Release (now unused) set to 296
- Subject changed from Unable to create location with organization_ids: [1] - Organizations is invalid to Unable to create location with organization_ids: [1] - Organizations is invalid
#3
Updated by Anonymous over 4 years ago
- % Done changed from 0 to 100
- Status changed from Ready For Testing to Closed
Applied in changeset ad61b8ca8da979ce51d383495bbc8b966ef433e5.
Fixes #22043 - Allow adding invalid orgs to locs (#5104)
And vice-versa. Currently when a taxonomy is invalid (e.g. because some
mismatch with hosts and resources), it cannot be assigned to the
opposite taxonomy. This is due to the fact that by default,
`has_and_belongs_to_many` associations validate the associated object as
well.