Skip to content

Conversation

@shravi903
Copy link

@shravi903 shravi903 commented Sep 22, 2025

https://accredible.atlassian.net/browse/HDR-3940

We store audited_changes as JSON parseable string: "{"a":1}" which can be parsed by Audit gem serializer: YAMLIfTextColumnType
But some data are incorrectly stored as non parseable string: {"a" => 1}" which gives raises Psych::SyntaxError https://app.bugsnag.com/accredible/acms-api/errors/68a4828815e70991bae806b3?filters[event.since]=30d&filters[error.status]=open&filters[search]=psych

It is unknown to me how such datas got stored in the very first place. I tried to find sources but couldn't find any. So my assumption is that such bad data got stored due to some temporary code changes which then later got corrected

Comment on lines +22 to +27
begin
ActiveRecord::Coders::YAMLColumn.new(Object).load(obj)
rescue Psych::SyntaxError
obj = obj.gsub("=>", ":")
ActiveRecord::Coders::YAMLColumn.new(Object).load(obj)
end
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First, Can we do it this way? To avoid parsing it twice?

Suggested change
begin
ActiveRecord::Coders::YAMLColumn.new(Object).load(obj)
rescue Psych::SyntaxError
obj = obj.gsub("=>", ":")
ActiveRecord::Coders::YAMLColumn.new(Object).load(obj)
end
begin
obj = obj.gsub("=>", ":")
ActiveRecord::Coders::YAMLColumn.new(Object).load(obj)
end

Second, what happens if we have a value like this `"{"a" => "some value include =>"}"? Could you test it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I don't want to modify a correct JSON parseable string which contains => for eq "{"a": "sample=>text"}"
  2. I don't think "{"a" => "some value include =>"}" is possible as the incorrect data also has pattern which is hash.to_s

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I don't want to modify a correct JSON parseable string which contains => for eq "{"a": "sample=>text"}"
  2. I don't think "{"a" => "some value include =>"}" is possible as the incorrect data also has pattern which is hash.to_s

why is "sample=>text" possible in the first point and not possible in the 2nd point? It should be possible in both, that's why we should find a safer way to replace "=>" with ":" in both cases.

Consider the following:

"{"a": "value of a has a =>"}"
"{"a" => "value of a has a =>"}"

both should be parsed as

"{"a": "value of a has a =>"}"
"{"a": "value of a has a =>"}"

but now, they are parsed as:

"{"a": "value of a has a =>"}"
"{"a": "value of a has a :"}" # this is wrong

I don't want to modify a correct JSON

If a json is already correct, then the proper replace function should not modify it. If a json contains "=>" in its value, we should not replace it.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a proper test coverage would be better

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

Successfully merging this pull request may close these issues.

3 participants