Skip to content

Binary partition-key affinity hashes serialized base64 text instead of bytes #74

Description

@dkropachev

Problem

Key-affinity routing for DynamoDB binary (B) partition keys hashes the value returned from the parsed botocore JSON request body. Botocore serializes binary values as base64 strings in JSON, so the affinity code hashes the base64 text bytes instead of the original binary value.

That can route binary partition keys to a different affinity node than the intended cross-language binary-key hash.

Evidence

A real botocore prepared PutItem with Item={"pk": {"B": b"\x00\x01stable"}} serializes to:

{"B": "AAFzdGFibGU="}

Current code:

  • alternator/core/key_affinity.py: _extract_typed_value() returns the raw parsed JSON value.
  • alternator/core/hashing.py: hash_attribute_value("B", value) encodes string values directly, so the base64 text is hashed.
  • tests/unit/test_key_affinity.py passes raw bytes, so it does not match real prepared-request shape.

Expected behavior

For B attributes parsed from request JSON, decode base64 text back to bytes before hashing. Raw bytes values should remain supported for direct/internal callers.

Test coverage needed

Add a test using a real botocore prepared request with a binary key and assert affinity selection matches hashing the original bytes, not the base64 string.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions