Refactor #34569

Postpone LookupValue match validations

Added by Ondřej Ezr 4 months ago. Updated 3 months ago.

Target version:
Bugzilla link:
Fixed in Releases:
Found in Releases:


match gets overriden by Rails if the record has been build by association e.g. ``
That basically means that any assigned value to match prior save is irrelevant because it will be replaced by Rails.

This was never an issue, because Rails just replaced the value with the same value as we've assigned, so it went unnoticed.
It only starts to cause issues once Rails had fixed a bug where it wrongly allowed foreign_key to be passed to <assoc>.build(foreign_key => value)
This is for sym vs string in hash keys as in reflection.foreign_key returned a symbol, but attribute is a string, so the assigned foreign key did not get filtered out properly.

This bug had been fixed in Rails 6.1 and the assigned foreign key is filtered out properly and our validations fail on presence of match as that gets assigned from host only after the Host is saved and thats after validation.

Related issues

Blocks Foreman - Tracker #28570: Rails 6.1 TrackerNew

Associated revisions

Revision 5a77b476 (diff)
Added by Ondřej Ezr 3 months ago

Fixes #34569 - postpone LookupValue#match validations

Validation for presence of foreign_key has to be postponed because of Rails internals. filters out foreign_key for given association because it assigns the value for that key after the main record gets saved.
This filtering did not work properly until Rails 6.1, thus we did not notice and thought it works.

Since Rails 6.1 works properly
and returns `foreing_key` in string format and thus filters out attributes from hashes where those passed as string keys.

All other validations can be run during validation if those allow nil value as the Rails assigned key should not need validation.


#1 Updated by The Foreman Bot 4 months ago

  • Assignee set to Ondřej Ezr
  • Status changed from New to Ready For Testing
  • Pull request added

#2 Updated by Ondřej Ezr 4 months ago

  • Parent task set to #28570

#3 Updated by Ondřej Ezr 4 months ago

  • Parent task deleted (#28570)

#4 Updated by Ondřej Ezr 4 months ago

#5 Updated by The Foreman Bot 3 months ago

  • Fixed in Releases 3.3.0 added

#6 Updated by Ondřej Ezr 3 months ago

  • Status changed from Ready For Testing to Closed

Also available in: Atom PDF