-
Notifications
You must be signed in to change notification settings - Fork 901
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
where_object_changes returns more records than expected #803
Comments
Minor improvements and additions to tests. Trying to reproduce issue #803.
Minor improvements and additions to tests. Trying to reproduce issue #803.
Minor improvements and additions to tests. Trying to reproduce issue #803.
Bug
ReproductionThis bug can be reproduced in the existing test suite by reverting part of 1ad7838. # spec/models/version_spec.rb
+ let(:int) { 1 }
- let(:int) { rand(5) + 2 } This patch will cause AnalysisConsider "versions"."object_changes" ILIKE '%"an_integer":[1,%'
OR "versions"."object_changes" ILIKE '%"an_integer":[%,1]%' See the problem yet? It's in the second half of the disjunction. Think about what those wildcards might match. What about a version record with
We don't want to match this record. We don't want SuggestionsI don't know how to fix this, so I might add a runtime warning to the method asking people to come here and join the discussion. Here are some ideas to get the conversation going. Have
|
I added the warning (in #979), it's been two months and 47,000 gem downloads, and no one has joined the discussion here, so I'll probably change the warning to an error in the next major release unless I hear from someone with a better idea. |
Closed by #993. To be released as 8.0.0. |
History --- [The first problem mention](paper-trail-gem@1ad7838). [The major issue](paper-trail-gem#803) with relevant discussions. Details --- I see the problem only with one specific case – when the method is `where_object_changes` and the serializer is YAML. Which is a default configuration. I see there are 6 types of queries with a numeric value for `where_object_changes` and `where_object` (grabbed from `version_spec.rb`): ``` SELECT "versions".* FROM "versions" WHERE "versions"."item_id" = 1 AND "versions"."item_type" = 'Widget' AND (object_changes @> '{"an_integer":[1]}') ORDER BY "versions"."created_at" ASC, "versions"."id" ASC SELECT "versions".* FROM "versions" WHERE "versions"."item_id" = 1 AND "versions"."item_type" = 'Widget' AND ("versions"."object_changes" ILIKE '% an_integer: - 1 %' OR "versions"."object_changes" ILIKE '% an_integer: -% - 1 %') ORDER BY "versions"."created_at" ASC, "versions"."id" ASC SELECT "versions".* FROM "versions" WHERE "versions"."item_id" = 1 AND "versions"."item_type" = 'Widget' AND (((object_changes->>'an_integer' ILIKE '[1,%') OR (object_changes->>'an_integer' ILIKE '[%,1]%'))) ORDER BY "versions"."created_at" ASC, "versions"."id" ASC SELECT "versions".* FROM "versions" WHERE (object @> '{"an_integer":1}') SELECT "versions".* FROM "versions" WHERE (object->>'an_integer' = '1') SELECT "versions".* FROM "versions" WHERE ("versions"."object" ILIKE '% an_integer: 1 %') ``` The only problematic one is `paper-trail-gem#2`. It incorrectly matches `object_changes` like ``` --- name: - - Kimberli an_integer: - - 0 created_at: - - 2017-09-28 18:30:13.369889000 Z updated_at: - - 2017-09-28 18:30:13.369889000 Z id: - - 1 --- name: - foobar - Hayes an_integer: - 77 - 1 updated_at: - 2017-09-28 18:30:13.383966000 Z - 2017-09-28 18:30:13.395539000 Z ```
History --- [The first problem mention](paper-trail-gem@1ad7838). [The major issue](paper-trail-gem#803) with relevant discussions. Details --- I see the problem only with one specific case – when the method is `where_object_changes` and the serializer is YAML. Which is a default configuration. I see there are 6 types of queries with a numeric value for `where_object_changes` and `where_object` (grabbed from `version_spec.rb`): ``` .where_object_changes N1 SELECT "versions".* FROM "versions" WHERE "versions"."item_id" = 1 AND "versions"."item_type" = 'Widget' AND (object_changes @> '{"an_integer":[1]}') ORDER BY "versions"."created_at" ASC, "versions"."id" ASC N1 SELECT "versions".* FROM "versions" WHERE "versions"."item_id" = 1 AND "versions"."item_type" = 'Widget' AND ("versions"."object_changes" ILIKE '% an_integer: - 1 %' OR "versions"."object_changes" ILIKE '% an_integer: -% - 1 %') ORDER BY "versions"."created_at" ASC, "versions"."id" ASC N3 SELECT "versions".* FROM "versions" WHERE "versions"."item_id" = 1 AND "versions"."item_type" = 'Widget' AND (((object_changes->>'an_integer' ILIKE '[1,%') OR (object_changes->>'an_integer' ILIKE '[%,1]%'))) ORDER BY "versions"."created_at" ASC, "versions"."id" ASC .where_object N4 SELECT "versions".* FROM "versions" WHERE (object @> '{"an_integer":1}') N5 SELECT "versions".* FROM "versions" WHERE (object->>'an_integer' = '1') N6 SELECT "versions".* FROM "versions" WHERE ("versions"."object" ILIKE '% an_integer: 1 %') ``` The only problematic one is N2. It incorrectly matches `object_changes` like ``` --- name: - - Kimberli an_integer: - - 0 created_at: - - 2017-09-28 18:30:13.369889000 Z updated_at: - - 2017-09-28 18:30:13.369889000 Z id: - - 1 --- name: - foobar - Hayes an_integer: - 77 - 1 updated_at: - 2017-09-28 18:30:13.383966000 Z - 2017-09-28 18:30:13.395539000 Z ```
History --- [The first problem mention](paper-trail-gem@1ad7838). [The major issue](paper-trail-gem#803) with relevant discussions. Details --- I see the problem only with one specific case – when the method is `where_object_changes` and the serializer is YAML. Which is a default configuration. I see there are 6 types of queries with a numeric value for `where_object_changes` and `where_object` (grabbed from `version_spec.rb`): ``` .where_object_changes N1 SELECT "versions".* FROM "versions" WHERE "versions"."item_id" = 1 AND "versions"."item_type" = 'Widget' AND (object_changes @> '{"an_integer":[1]}') ORDER BY "versions"."created_at" ASC, "versions"."id" ASC N1 SELECT "versions".* FROM "versions" WHERE "versions"."item_id" = 1 AND "versions"."item_type" = 'Widget' AND ("versions"."object_changes" ILIKE '% an_integer: - 1 %' OR "versions"."object_changes" ILIKE '% an_integer: -% - 1 %') ORDER BY "versions"."created_at" ASC, "versions"."id" ASC N3 SELECT "versions".* FROM "versions" WHERE "versions"."item_id" = 1 AND "versions"."item_type" = 'Widget' AND (((object_changes->>'an_integer' ILIKE '[1,%') OR (object_changes->>'an_integer' ILIKE '[%,1]%'))) ORDER BY "versions"."created_at" ASC, "versions"."id" ASC .where_object N4 SELECT "versions".* FROM "versions" WHERE (object @> '{"an_integer":1}') N5 SELECT "versions".* FROM "versions" WHERE (object->>'an_integer' = '1') N6 SELECT "versions".* FROM "versions" WHERE ("versions"."object" ILIKE '% an_integer: 1 %') ``` The only problematic one is N2. It incorrectly matches `object_changes` like ``` --- name: - - Kimberli an_integer: - - 0 created_at: - - 2017-09-28 18:30:13.369889000 Z updated_at: - - 2017-09-28 18:30:13.369889000 Z id: - - 1 --- name: - foobar - Hayes an_integer: - 77 - 1 updated_at: - 2017-09-28 18:30:13.383966000 Z - 2017-09-28 18:30:13.395539000 Z ```
* clarify the issue with `where_object_changes` for numeric values History --- [The first problem mention](1ad7838). [The major issue](#803) with relevant discussions. Details --- I see the problem only with one specific case – when the method is `where_object_changes` and the serializer is YAML. Which is a default configuration. I see there are 6 types of queries with a numeric value for `where_object_changes` and `where_object` (grabbed from `version_spec.rb`): ``` .where_object_changes N1 SELECT "versions".* FROM "versions" WHERE "versions"."item_id" = 1 AND "versions"."item_type" = 'Widget' AND (object_changes @> '{"an_integer":[1]}') ORDER BY "versions"."created_at" ASC, "versions"."id" ASC N1 SELECT "versions".* FROM "versions" WHERE "versions"."item_id" = 1 AND "versions"."item_type" = 'Widget' AND ("versions"."object_changes" ILIKE '% an_integer: - 1 %' OR "versions"."object_changes" ILIKE '% an_integer: -% - 1 %') ORDER BY "versions"."created_at" ASC, "versions"."id" ASC N3 SELECT "versions".* FROM "versions" WHERE "versions"."item_id" = 1 AND "versions"."item_type" = 'Widget' AND (((object_changes->>'an_integer' ILIKE '[1,%') OR (object_changes->>'an_integer' ILIKE '[%,1]%'))) ORDER BY "versions"."created_at" ASC, "versions"."id" ASC .where_object N4 SELECT "versions".* FROM "versions" WHERE (object @> '{"an_integer":1}') N5 SELECT "versions".* FROM "versions" WHERE (object->>'an_integer' = '1') N6 SELECT "versions".* FROM "versions" WHERE ("versions"."object" ILIKE '% an_integer: 1 %') ``` The only problematic one is N2. It incorrectly matches `object_changes` like ``` --- name: - - Kimberli an_integer: - - 0 created_at: - - 2017-09-28 18:30:13.369889000 Z updated_at: - - 2017-09-28 18:30:13.369889000 Z id: - - 1 --- name: - foobar - Hayes an_integer: - 77 - 1 updated_at: - 2017-09-28 18:30:13.383966000 Z - 2017-09-28 18:30:13.395539000 Z ```
See discussion at paper-trail-gem#803
* clarify the issue with `where_object_changes` for numeric values History --- [The first problem mention](paper-trail-gem@1ad7838). [The major issue](paper-trail-gem#803) with relevant discussions. Details --- I see the problem only with one specific case – when the method is `where_object_changes` and the serializer is YAML. Which is a default configuration. I see there are 6 types of queries with a numeric value for `where_object_changes` and `where_object` (grabbed from `version_spec.rb`): ``` .where_object_changes N1 SELECT "versions".* FROM "versions" WHERE "versions"."item_id" = 1 AND "versions"."item_type" = 'Widget' AND (object_changes @> '{"an_integer":[1]}') ORDER BY "versions"."created_at" ASC, "versions"."id" ASC N1 SELECT "versions".* FROM "versions" WHERE "versions"."item_id" = 1 AND "versions"."item_type" = 'Widget' AND ("versions"."object_changes" ILIKE '% an_integer: - 1 %' OR "versions"."object_changes" ILIKE '% an_integer: -% - 1 %') ORDER BY "versions"."created_at" ASC, "versions"."id" ASC N3 SELECT "versions".* FROM "versions" WHERE "versions"."item_id" = 1 AND "versions"."item_type" = 'Widget' AND (((object_changes->>'an_integer' ILIKE '[1,%') OR (object_changes->>'an_integer' ILIKE '[%,1]%'))) ORDER BY "versions"."created_at" ASC, "versions"."id" ASC .where_object N4 SELECT "versions".* FROM "versions" WHERE (object @> '{"an_integer":1}') N5 SELECT "versions".* FROM "versions" WHERE (object->>'an_integer' = '1') N6 SELECT "versions".* FROM "versions" WHERE ("versions"."object" ILIKE '% an_integer: 1 %') ``` The only problematic one is N2. It incorrectly matches `object_changes` like ``` --- name: - - Kimberli an_integer: - - 0 created_at: - - 2017-09-28 18:30:13.369889000 Z updated_at: - - 2017-09-28 18:30:13.369889000 Z id: - - 1 --- name: - foobar - Hayes an_integer: - 77 - 1 updated_at: - 2017-09-28 18:30:13.383966000 Z - 2017-09-28 18:30:13.395539000 Z ```
The readme says:
I asked Ben about this in https://github.com/airblade/paper_trail/pull/801/files
What should our next step be in troubleshooting this? Can we get a failing test by reverting 1ad7838, or should we write a new test?
The text was updated successfully, but these errors were encountered: