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

History updates rewrite all historical models #167

Closed
tagliala opened this issue May 28, 2022 · 2 comments · Fixed by #168
Closed

History updates rewrite all historical models #167

tagliala opened this issue May 28, 2022 · 2 comments · Fixed by #168
Labels
bug CRITICAL Critical issues

Comments

@tagliala
Copy link
Member

It happens because the search does not look for HID but for ID

Specs are not checking that other models in the history, and if this is by design it is not clear from the readme

https://github.com/ifad/chronomodel#history-manipulation

History manipulation
History objects can be changed and .saved just like any other record. They cannot be deleted.

[11] pry(main)> country = Country.create! name: 'C0'
  TRANSACTION (0.3ms)  BEGIN
  Country Create (0.7ms)  INSERT INTO "countries" ("name", "created_at", "updated_at") VALUES ($1, $2, $3) RETURNING "id"  [["name", "C0"], ["created_at", "2022-05-28 16:32:53.299754"], ["updated_at", "2022-05-28 16:32:53.299754"]]
  TRANSACTION (0.8ms)  COMMIT
=> #<Country:0x00007fd5f8ba19d8
 id: 4,
 name: "C0",
 created_at: Sat, 28 May 2022 16:32:53.299754000 UTC +00:00,
 updated_at: Sat, 28 May 2022 16:32:53.299754000 UTC +00:00>
[12] pry(main)> country.update name: 'C1'
  TRANSACTION (0.4ms)  BEGIN
  Country Update (1.0ms)  UPDATE "countries" SET "name" = $1, "updated_at" = $2 WHERE "countries"."id" = $3  [["name", "C1"], ["updated_at", "2022-05-28 16:32:59.823213"], ["id", 4]]
  TRANSACTION (1.0ms)  COMMIT
=> true
[13] pry(main)> country.history
  Country::History Load (0.7ms)  SELECT "history"."countries".* FROM "history"."countries" WHERE "history"."countries"."id" = $1 ORDER BY lower(validity) ASC  [["id", 4]]
=> [#<Country::History:0x00007fd5f8d268a8
  id: 4,
  name: "C0",
  created_at: Sat, 28 May 2022 16:32:53.299754000 UTC +00:00,
  updated_at: Sat, 28 May 2022 16:32:53.299754000 UTC +00:00,
  hid: 5,
  validity: [2022-05-28 16:32:53.300513 UTC, 2022-05-28 16:32:59.824341 UTC],
  recorded_at: Sat, 28 May 2022 16:32:53.300513000 UTC +00:00>,
 #<Country::History:0x00007fd5f8d266c8
  id: 4,
  name: "C1",
  created_at: Sat, 28 May 2022 16:32:53.299754000 UTC +00:00,
  updated_at: Sat, 28 May 2022 16:32:59.823213000 UTC +00:00,
  hid: 6,
  validity: [2022-05-28 16:32:59.824341 UTC, nil],
  recorded_at: Sat, 28 May 2022 16:32:59.824341000 UTC +00:00>]
[14] pry(main)> country.history.last.update name: 'C2'
  Country::History Load (1.3ms)  SELECT "history"."countries".* FROM "history"."countries" WHERE "history"."countries"."id" = $1 ORDER BY lower(validity) DESC LIMIT $2  [["id", 4], ["LIMIT", 1]]
  TRANSACTION (0.2ms)  BEGIN
  Country::History Update (0.4ms)  UPDATE "history"."countries" SET "name" = $1, "updated_at" = $2 WHERE "history"."countries"."id" = $3  [["name", "C2"], ["updated_at", "2022-05-28 16:33:18.260290"], ["id", 4]]
  TRANSACTION (1.0ms)  COMMIT
=> true
[15] pry(main)> country.history
  Country::History Load (0.6ms)  SELECT "history"."countries".* FROM "history"."countries" WHERE "history"."countries"."id" = $1 ORDER BY lower(validity) ASC  [["id", 4]]
=> [#<Country::History:0x00007fd5f98191c0
  id: 4,
  name: "C2",
  created_at: Sat, 28 May 2022 16:32:53.299754000 UTC +00:00,
  updated_at: Sat, 28 May 2022 16:33:18.260290000 UTC +00:00,
  hid: 5,
  validity: [2022-05-28 16:32:53.300513 UTC, 2022-05-28 16:32:59.824341 UTC],
  recorded_at: Sat, 28 May 2022 16:32:53.300513000 UTC +00:00>,
 #<Country::History:0x00007fd5f9818e78
  id: 4,
  name: "C2",
  created_at: Sat, 28 May 2022 16:32:53.299754000 UTC +00:00,
  updated_at: Sat, 28 May 2022 16:33:18.260290000 UTC +00:00,
  hid: 6,
  validity: [2022-05-28 16:32:59.824341 UTC, nil],
  recorded_at: Sat, 28 May 2022 16:32:59.824341000 UTC +00:00>]
[16] pry(main)> 
@tagliala tagliala added the bug label May 28, 2022
@tagliala
Copy link
Member Author

Regression introduced from 5.2 to 6.0

@tagliala tagliala added the CRITICAL Critical issues label May 28, 2022
@tagliala
Copy link
Member Author

bisected to rails/rails@b6828fc

Ref: rails/rails#35987

tagliala added a commit that referenced this issue May 28, 2022
Temporarily change primary key object instance variable to `:hid` to
prevent unwanted changes to the whole history

Fix #167
tagliala added a commit that referenced this issue May 28, 2022
Temporarily change primary key object instance variable to `:hid` to
prevent unwanted changes to the whole history

Fix #167
tagliala added a commit that referenced this issue May 28, 2022
Temporarily change primary key object instance variable to `:hid` to
prevent unwanted changes to the whole history

Fix #167

Ref: 
- rails/rails@b6828fc
- rails/rails#35987
tagliala added a commit that referenced this issue May 28, 2022
Temporarily change primary key object instance variable to `:hid` to
prevent unwanted changes to the whole history

Fix #167

Ref: 
- rails/rails@b6828fc
- rails/rails#35987
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug CRITICAL Critical issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant