On Thursday, June 21, 2018 at 1:38:56 PM UTC-7, [email protected] 
wrote:
>
> Hi Jeremy,
>
> Stumbled upon this issue when attempting to upgrade Sequel from 4.12.0 for 
> Citygram <https://github.com/codeforamerica/citygram>.
>
> This project currently attempts to validate fields that are serialized as 
> GeoJSON before they are serialized via a Sequel plugin:
>
> Validation: 
> https://github.com/codeforamerica/citygram/blob/b2c1faa513c570cf19a5da1aa8dcbd314cba7755/app/models/event.rb#L35
> Plugin: 
> https://github.com/codeforamerica/citygram/blob/b2c1faa513c570cf19a5da1aa8dcbd314cba7755/lib/sequel/plugins/geometry_validation.rb
>
> With the change you mentioned, which I tracked to 
> https://github.com/jeremyevans/sequel/commit/c61a63994, it does indeed 
> attempt to serialize as GeoJSON before the validation. This ends up 
> resulting in more opaque error messages as the exceptions bubble up from 
> the serializer. I.e. we get things like `undefined method `[]' for 
> nil:NilClass` rather than `geom is an invalid geometry`.
>
> I understand why this change was made (to allow validation of the actual 
> data being inserted into the database), but do you (or anyone else :) have 
> suggestions for how we might preserve this error handling behavior?
>

I think the simplest approach would be to change validates_geometry to look 
at @deserialized_values if geom is a String:

def validates_geometry(atts, opts = {})
  atts.each do |att|
    v = send(att)
    if v.is_a?(String) && (dv = deserialized_values[att]) && 
!valid_geometry?(dv)
      errors.add(att, opts[:message] || 'is an invalid geometry')
    end
  end
end

If you need to have validates_geometry work when not using the 
serialization, that's a little more work, but not too much.

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to