Project

General

Profile

Bug #16389

Can't create taxable e.g. domain object if I'm in context of specific organization or location

Added by Marek Hulán over 4 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Organizations and Locations
Target version:
Difficulty:
Triaged:
Bugzilla link:
Fixed in Releases:
Found in Releases:

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 issues

Related to OpenSCAP - Bug #16229: Invalid Taxable taxonomies when creating policy through UIClosed2016-08-22
Related to Foreman - Tracker #10022: Taxonomies related issuesNew2015-04-05

Related to Foreman - Bug #4731: Creating domain when organization selected produces duplicate key errorClosed2014-03-19
Related to Foreman - Bug #16463: with_taxonomy_scope returns all objects when no taxable ids availableClosed2016-09-07
Has duplicate Foreman - Bug #16471: Cannot create Host Group: Taxable taxonomies is invalidDuplicate2016-09-07

Associated revisions

Revision 35ed04f9 (diff)
Added by Marek Hulán over 4 years ago

Fixes #16389 - enable taxable object creation in specific context

Revision e0b91994 (diff)
Added by Marek Hulán about 4 years ago

Fixes #16389 - enable taxable object creation in specific context

(cherry picked from commit 35ed04f95f14c934ffebc874e90a3a4a6684fe71)

History

#1 Updated by Marek Hulán over 4 years ago

  • Related to Bug #16229: Invalid Taxable taxonomies when creating policy through UI added

#2 Updated by Marek Hulán over 4 years ago

#3 Updated by Marek Hulán over 4 years ago

  • Related to Bug #4731: Creating domain when organization selected produces duplicate key error added

#4 Updated by Marek Hulán over 4 years ago

  • Status changed from New to Assigned
  • Assignee set to Marek Hulán

#5 Updated by The Foreman Bot over 4 years ago

  • Status changed from Assigned to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/3801 added

#6 Updated by Marek Hulán over 4 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.

#7 Updated by Marek Hulán over 4 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

#8 Updated by Marek Hulán over 4 years ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100

#9 Updated by Dominic Cleal about 4 years ago

  • Legacy Backlogs Release (now unused) set to 181

#10 Updated by Marek Hulán about 4 years ago

  • Target version set to 1.6.0

#11 Updated by Dominic Cleal about 4 years ago

  • Related to Bug #16463: with_taxonomy_scope returns all objects when no taxable ids available added

#12 Updated by Dominic Cleal about 4 years ago

  • Has duplicate Bug #16471: Cannot create Host Group: Taxable taxonomies is invalid added

Also available in: Atom PDF