Fix batch send_key crash in #size (use user_key_as_value)#17
Merged
Conversation
BatchWrite#size, BatchUDF#size, and BatchDelete#size raised NoMethodError: undefined method 'estimate_size' for a String whenever the batch policy had send_key: true, crashing batch_operate before any I/O. Key#user_key returns the unwrapped raw value, but #estimate_size is defined only on Aerospike::Value. Use #user_key_as_value instead, matching the single-record write path in command.rb. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
mknapik
approved these changes
Jul 2, 2026
mknapik
approved these changes
Jul 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
BatchWrite#size,BatchUDF#size, andBatchDelete#sizeraisedNoMethodError: undefined method 'estimate_size' for an instance of Stringwhenever the batch record's policy hadsend_key: true. Since#sizeruns while estimating the wire buffer duringbatch_operate, any batch withsend_keycrashed before reaching the network.Root cause
The three
#sizemethods called@key.user_key.estimate_size, butKey#user_keyreturns the unwrapped raw value (@user_key.get→String/Integer), and#estimate_sizeis defined only onAerospike::Value. The single-record write path incommand.rbalready does this correctly viauser_key_as_value.Fix
Replace
@key.user_key.estimate_sizewith@key.user_key_as_value.estimate_sizein:lib/aerospike/batch_write.rblib/aerospike/batch_udf.rblib/aerospike/batch_delete.rbVerification
Reproduction from the report now runs cleanly for all three classes (previously raised):
🤖 Generated with Claude Code