Skip to content

#515: Preserve original _id in overwrite and delete_one on decorated factbases#522

Closed
VasilevNStas wants to merge 1 commit into
zerocracy:masterfrom
VasilevNStas:fix/515-overwrite-preserve-id
Closed

#515: Preserve original _id in overwrite and delete_one on decorated factbases#522
VasilevNStas wants to merge 1 commit into
zerocracy:masterfrom
VasilevNStas:fix/515-overwrite-preserve-id

Conversation

@VasilevNStas

Copy link
Copy Markdown
Contributor

Description

Fbe.overwrite and Fbe.delete_one use delete-and-recreate when the property already exists. On a Fbe.fb-decorated factbase, the Factbase::Pre hook assigns a fresh _id ((max _id) + 1) on every insert, and the recreation loop skipped _id because it was already set. The original _id was lost, breaking external references.

Fix

Added Fbe.unid helper that removes the _id property from the fact's internal map after the Pre hook fires but before the recreation loop runs. The loop then sees _id as nil and restores the original value from before.

Affected paths:

  • Fbe.overwrite hash path (line 54-65)
  • Fbe.overwrite scalar path (line 86-98)
  • Fbe.delete_one (line 34-42)

Closes #515

Tests

  • test_preserves_id_on_decorated_fb — scalar overwrite on Fbe.fb-decorated factbase with 3 facts
  • test_preserves_id_on_decorated_fb_with_hash — hash overwrite on decorated factbase
  • test_preserves_id_on_decorated_fb (delete_one) — delete_one on decorated factbase

Verification

  • bundle exec rubocop — 0 offenses
  • bundle exec rake test — 286 tests, 0 failures

@VasilevNStas VasilevNStas changed the title fix: preserve original _id in overwrite and delete_one on decorated factbases #515 fix: preserve original _id in overwrite and delete_one on decorated factbases Jun 8, 2026
@VasilevNStas VasilevNStas changed the title #515 fix: preserve original _id in overwrite and delete_one on decorated factbases #515: Preserve original _id in overwrite and delete_one on decorated factbases Jun 8, 2026
@VasilevNStas

Copy link
Copy Markdown
Contributor Author

@yegor256 please review

@VasilevNStas

Copy link
Copy Markdown
Contributor Author

Closing per @yegor256 feedback: the approach needs architectural approval first. Moved discussion to #515.

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.overwrite and Fbe.delete_one reassign _id on the delete-and-recreate path when fb is Fbe.fb-decorated

1 participant