You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
causes a JSON::ParserError (unexpected end of input)
the reason is that image_data is stored as text (empty string "") and not as nil, whilst Shrine expects nil or valid JSON.
this still was no problem with ruby 3.2.5 and rails 7.0
work around:
# lib/shrine/plugins/handle_empty_strings.rbclassShrinemodulePluginsmoduleHandleEmptyStringsmoduleAttacherClassMethods# Override the class method that initializes attachers from column datadeffrom_column(data, **options)data=nilifdata.is_a?(String) && data.empty?super(data, **options)endendmoduleAttacherMethods# Override instance method for loading from columndefload_column(data)data=nilifdata.is_a?(String) && data.empty?super(data)endprivate# Override deserialization methoddefdeserialize_column(data)data=nilifdata.is_a?(String) && data.empty?super(data)endenddefself.configure(uploader)# No need to try to access internal constantsendendregister_plugin(:handle_empty_strings,HandleEmptyStrings)endend
add it first in initializers:
Shrine.plugin:handle_empty_strings
and that is not enough, also added in initializers: shrine_json_serializer_patch.rb
# config/initializers/shrine_json_serializer_patch.rb# This needs to be loaded after Shrine is initializedRails.application.config.after_initializedo# Find the JsonSerializer class used by Shrineifdefined?(Shrine::Plugins::Column::JsonSerializer)json_serializer=Shrine::Plugins::Column::JsonSerializerelse# Try to find it through the Shrine optionsshrine_class=Shrinejson_serializer=shrine_class.opts[:column][:serializer]end# Patch the load method to handle empty stringsifjson_serializerjson_serializer.singleton_class.prepend(Module.newdodefload(data)returnnilifdata.is_a?(String) && data.empty?superendend)endend
Would you fix this?
Thanks, Daniela (supported by Claude 3.7)
The text was updated successfully, but these errors were encountered:
Hi,
with ruby 3.4.2 and rails 7.2.
adding (in my case to class Document)
or
causes a JSON::ParserError (unexpected end of input)
the reason is that image_data is stored as text (empty string "") and not as nil, whilst Shrine expects nil or valid JSON.
this still was no problem with ruby 3.2.5 and rails 7.0
work around:
add it first in initializers:
and that is not enough, also added in initializers: shrine_json_serializer_patch.rb
Would you fix this?
Thanks, Daniela (supported by Claude 3.7)
The text was updated successfully, but these errors were encountered: