Bug #16389
closed
Can't create taxable e.g. domain object if I'm in context of specific organization or location
Added by Marek Hulán almost 8 years ago.
Updated about 6 years ago.
Category:
Organizations and Locations
|
Description
Steps to reproduce:
1) make sure you have organization, e.g. org A
2) switch to org A in context selector
3) go to domain
4) create a domain assigned to org A, this might still work
5) try to create new one again assigned to org A (should be preselected since you're in its context), it will stuck on the creation form displaying no errors and you can find "Failed to save: Taxable taxonomies is invalid" in log (if you have at least info level enabled)
to reproduce from console
# make sure there's at least one Domain in Organization.first
Organization.current = Organization.first
d = Domain.new :organization_ids => [1]
d.valid? # => false
d.taxable_taxonomies # return invalid taxable taxonomies linked to other (existing!) domain
Cause:
It seems that default scope added by taxonomies registers ids of existing records which gets picked by https://github.com/rails/rails/blob/v4.2.7.1/activerecord/lib/active_record/scoping/named.rb#L39:AR when it creates associations. A workaround is to do Domain.unscoped.new
- Related to Bug #16229: Invalid Taxable taxonomies when creating policy through UI added
- Related to Bug #4731: Creating domain when organization selected produces duplicate key error added
- Status changed from New to Assigned
- Assignee set to Marek Hulán
- Status changed from Assigned to Ready For Testing
- Pull request https://github.com/theforeman/foreman/pull/3801 added
A proper fix should probably go to rails - https://github.com/rails/rails/pull/26342 but it's unrealistic to expect having this available anytime soon. Meanwhile, we can expand our existing hack to workaround it.
Since the upstream fix was declined, we have to solve it in Foreman. Probably less hacky way is to generate the part of SQL as a string so AREL can't parse it and register the condition for new instance, e.g.
Domain.where(id: 1).new.id # => 1
Domain.where('id IN (1)').new.id # => nil
- Status changed from Ready For Testing to Closed
- % Done changed from 0 to 100
- Translation missing: en.field_release set to 181
- Target version set to 1.6.0
- Related to Bug #16463: with_taxonomy_scope returns all objects when no taxable ids available added
- Has duplicate Bug #16471: Cannot create Host Group: Taxable taxonomies is invalid added
Also available in: Atom
PDF