Project

General

Profile

Actions

Refactor #34569

closed

Postpone LookupValue match validations

Added by Ondřej Ezr over 2 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Rails
Target version:
-
Difficulty:
Triaged:
No
Fixed in Releases:
Found in Releases:

Description

match gets overriden by Rails if the record has been build by association e.g. `host.lookup_values.build()`
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 https://github.com/rails/rails/blob/13cdd7a6aef86b23c3410adff1d4f6eeefc72c67/activerecord/lib/active_record/associations/association.rb#L196 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 1 (0 open1 closed)

Blocks Foreman - Tracker #28570: Rails 6.1 TrackerClosed

Actions
Actions

Also available in: Atom PDF