Skip to content

#542 preserve _id, _time, _version, _job on Fbe.delete recreate path#545

Merged
yegor256 merged 1 commit into
zerocracy:masterfrom
edmoffo:542-delete-preserve-system-props
Jun 8, 2026
Merged

#542 preserve _id, _time, _version, _job on Fbe.delete recreate path#545
yegor256 merged 1 commit into
zerocracy:masterfrom
edmoffo:542-delete-preserve-system-props

Conversation

@edmoffo

@edmoffo edmoffo commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Issue #542 reports that Fbe.delete reassigns the four system properties whenever the factbase is decorated by Fbe.fb. The destroy-and-recreate cycle in lib/fbe/delete.rb deleted _id from the snapshot up front, then routed the recreated fact through the Factbase::Pre block that assigns _id, _time, _version, and _job on insert, and the restoration loop's next unless c[k].nil? guard refused to overwrite the Pre-assigned values. Any external reference to the original _id, including follower facts and later (eq _id N) lookups, was left dangling.

The fix strips the four system properties from the new fact's internal map after Pre fires but before the restoration loop runs, so the loop carries the original values forward. before.delete(id) is gone, so _id survives into the snapshot like the rest. test_deletes_safely continues to pass because its single-fact factbase still produces the same _id value, while a new test_preserves_system_props_on_decorated_fb pins the contract against a two-fact factbase where the Pre arithmetic would otherwise drift.

Verification on this branch: bundle exec ruby -Ilib -Itest test/fbe/test_delete.rb reports 10 tests, 21 assertions, 0 failures, 0 errors, 0 skips; rubocop lib/fbe/delete.rb test/fbe/test_delete.rb reports 0 offenses. Reverting only the lib/fbe/delete.rb change flips the new test to Expected: 1, Actual: 3, confirming it catches the bug.

Closes #542

…recreate path

Strip the four system properties from the new fact's internal map after
Factbase::Pre fires so the restoration loop carries the original values
forward instead of the Pre-assigned ones.
@yegor256 yegor256 merged commit 4318276 into zerocracy:master Jun 8, 2026
10 checks passed
@0crat

0crat commented Jun 8, 2026

Copy link
Copy Markdown

@edmoffo Thank you for your contribution! Based on our team policy, you've earned +24 points for this code submission. This reward reflects the base points awarded for providing a review contribution. Your running score is +1851. Please keep the contributions coming and don't forget to check your Zerocracy account as well!

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.

Fbe.delete reassigns _id, _time, _version, _job on the delete-and-recreate path when fb is Fbe.fb-decorated

3 participants