hyper-mesh icon indicating copy to clipboard operation
hyper-mesh copied to clipboard

Need spec for using the Model.find_by(attribute => value) scope in pre-rendering.

Open adamcreekroad opened this issue 6 years ago • 0 comments

A bug was discovered in staging and production environments only, pre-rendering was breaking with the error RuntimeError (HyperModel fetching records failed, exception caught when applying ["find_by_nickname", "adamcreekroad"] to db object User: method missing):

It is really weird that this was working fine in development...

The fix was pushed in the latest edge branch, but it needs a spec written.

f.when_on_server { @server_data_cache[klass, ["find_by_#{attribute}", value], :id] }

Was changed to:

f.when_on_server { @server_data_cache[klass, ["find_by", { attribute => value }], 'id'] }

There were amazingly two things broken here only in staging and production:

  1. find_by_attribute(value)'s secure method was undefined and throwing that original error.
  2. @value.attributes.has_key?(method) was returning false when method was :id, which that when_on_server call up there passes through. attributes is a hash of String => String, so checking for a symbol was not working.

adamcreekroad avatar Feb 28 '18 21:02 adamcreekroad