Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with backslash on forestadmin-schema.json #623

Open
clavat opened this issue May 25, 2023 · 1 comment
Open

Issue with backslash on forestadmin-schema.json #623

clavat opened this issue May 25, 2023 · 1 comment

Comments

@clavat
Copy link

clavat commented May 25, 2023

Expected behavior

Wellformed .forestadmin-schema.json

Actual behavior

Malformed .forestadmin-schema.json because it try to espace backslash from schema.rb
image

Failure Logs

This come from my Production server when I try to deploy ForestAdmin for the first time.

2023-05-25 15:03:33.923134771 +0200 CEST [postdeploy-8568] [2023-05-25 13:03:33] Forest 🌳🌳🌳 The content of .forestadmin-schema.json file is not a correct JSON. 2023-05-25 15:03:33.923138396 +0200 CEST [postdeploy-8568] [2023-05-25 13:03:33] Forest 🌳🌳🌳 The schema cannot be synchronized with Forest Admin servers. 2023-05-25 15:03:33.947271238 +0200 CEST [postdeploy-8568] /app/vendor/ruby-2.7.7/lib/ruby/2.7.0/tsort.rb:228:in block in tsort_each'
2023-05-25 15:03:33.947272161 +0200 CEST [postdeploy-8568] /app/vendor/ruby-2.7.7/lib/ruby/2.7.0/tsort.rb:431:in each_strongly_connected_component_from'

Context

In my project I have a jsonb column with a default value at database level, this default value include a backslash followed by a double quote, it look like this :
t.jsonb "quote_char", default: [{"value"=>"\""}], null: false

  • Package Version: 8.0.8
  • Rails Version: 6.1
  • Database Dialect: SQL
  • Database Version: PostgreSQL 13
@clavat
Copy link
Author

clavat commented May 25, 2023

FYI, I'd monkey patch your lib this way to make things work on our project :

# frozen_string_literal: true

module ForestLiana
  # This class is used as a file generator for the ForestLiana gem.
  class SchemaFileUpdater
    def perform
      File.open(@filename, 'w') do |file|
        # NOTICE: Escape '\' characters to ensure the generation of valid JSON files. It fixes
        #         potential issues if some fields have validations using complex regexp.
        file.puts pretty_print({ # rubocop:disable Rails/Output
                                 collections: @collections,
                                 meta: @meta
                               }).gsub(/[^\\](\\)[^\\"]/) { |x| x.gsub(Regexp.last_match(1), '\\\\\\') }.gsub(/("\\\\")/, '"\\\\\\\\\"')
      end
    end
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant