Bug #16389
closedCan't create taxable e.g. domain object if I'm in context of specific organization or location
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
Updated by Marek Hulán over 8 years ago
- Related to Bug #16229: Invalid Taxable taxonomies when creating policy through UI added
Updated by Marek Hulán over 8 years ago
- Related to Tracker #10022: Taxonomies related issues added
Updated by Marek Hulán over 8 years ago
- Related to Bug #4731: Creating domain when organization selected produces duplicate key error added
Updated by Marek Hulán over 8 years ago
- Status changed from New to Assigned
- Assignee set to Marek Hulán
Updated by The Foreman Bot over 8 years ago
- Status changed from Assigned to Ready For Testing
- Pull request https://github.com/theforeman/foreman/pull/3801 added
Updated by Marek Hulán over 8 years ago
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.
Updated by Marek Hulán over 8 years ago
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
Updated by Marek Hulán over 8 years ago
- Status changed from Ready For Testing to Closed
- % Done changed from 0 to 100
Applied in changeset 35ed04f95f14c934ffebc874e90a3a4a6684fe71.
Updated by Dominic Cleal over 8 years ago
- Translation missing: en.field_release set to 181
Updated by Dominic Cleal over 8 years ago
- Related to Bug #16463: with_taxonomy_scope returns all objects when no taxable ids available added
Updated by Dominic Cleal over 8 years ago
- Has duplicate Bug #16471: Cannot create Host Group: Taxable taxonomies is invalid added