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? Thank you! -Jesse On Wednesday, October 29, 2014 at 11:37:58 AM UTC-7, [email protected] wrote: > > I got real late to see this reply. > > Once I find some space during the project to look into this, I'll consider > moving to PostgreSQL JSON columns. I could coincide with you in that > AR::Store is not a good idea if you have PSQL underneath, but for the cases > when you don't, having it seems like a good workaround. > > Thanks for your answer. I'll let you know if I get to a better solution. > > On Monday, September 22, 2014 5:56:31 PM UTC-3, Jeremy Evans wrote: >> >> On Monday, September 22, 2014 1:49:04 PM UTC-7, Jeremy Evans wrote: >>> >>> Sequel doesn't currently have a plugin for ActiveRecord::Store like >>> functionality. Personally, I think it's just a bad idea. If you are using >>> PostgreSQL, my recommendation would be to use a native json column with >>> Sequel's pg_json extension, and instead of using attr_accessor, just add >>> instance methods that get/set the value in the json hash: >>> >> >> I should point out that if you aren't using PostgreSQL, you can use the >> serialization plugin as you are doing currently, and the code below will >> work. Basically, your issue is you are keeping track of the data in two >> separate places (instance variables and the deserialized json hash), >> instead of a single place. If you just keep track of it in a single place, >> as the code below does, you are fine, assuming you aren't actually >> modifying attr1 or attr2 during the call to save. >> >> Thanks, >> Jeremy >> >> >>> >>> class Example < Sequel::Model >>> def attr1 >>> data['attr1'] >>> end >>> >>> def attr1=(v) >>> modified!(:data) >>> data['attr1'] = v >>> end >>> >>> def attr2 >>> data['attr2'] >>> end >>> >>> def attr2=(v) >>> modified!(:data) >>> data['attr2'] = v >>> end >>> >>> def validate >>> validates_presence [:attr1, :attr2] >>> end >>> end >>> >> -- 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.
