Skip to content

Metadata not attached to CompareExchangeValue after executing get_compare_exchange_value #291

@slidwell44

Description

@slidwell44

When creating a Compare Exhange Item and attaching metadata such as:

with self.document_store.open_session(
    session_options=SessionOptions(
        transaction_mode=TransactionMode.CLUSTER_WIDE
    )
) as session:
    value: CompareExchangeValue[DocumentsCompareExchangeItem] = (
        session.advanced.cluster_transaction.create_compare_exchange_value(
            key=self.compare_exchange_key,
            item=item,
        )
    )

    value.metadata["@expires"] = (
        pendulum.now("UTC")
        .add(seconds=lock_for_seconds)
        .to_iso8601_string()
    )

    value.metadata["@created-at"] = pendulum.now("UTC").to_iso8601_string()

    session.save_changes()

The Compare Exchange Item is successfully stored in RavenDB server with metadata:

{
    "@expires": "2026-04-15T18:27:51.556029Z",
    "@created-at": "2026-04-15T12:27:51.556568Z"
}

However, when attempting to get_compare_exchange_value, I raise a ValueError because current_lock.metadata["@created-at"] does not exist in the CompareExchangeValue, nor does any metadata according to the CompareExchangeValue:

with self.document_store.open_session(
    session_options=SessionOptions(
        transaction_mode=TransactionMode.CLUSTER_WIDE
    )
) as session:
    current_lock: (
        CompareExchangeValue[DocumentsCompareExchangeItem] | None
    ) = session.advanced.cluster_transaction.get_compare_exchange_value(
        key=self.compare_exchange_key,
        object_type=DocumentsCompareExchangeItem,
    )

if not current_lock.has_metadata:
    raise ValueError

Raises:

Traceback (most recent call last):
  File "C:\Users\sl3789\Documents\projs\productvisionapi\app\documents\services.py", line 77, in _refresh_document_search
    lock = r.acquire_process_lock(DOCUMENT_EXPIRATION_SECONDS)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\sl3789\Documents\projs\productvisionapi\app\documents\repositories.py", line 260, in acquire_process_lock
    raise ValueError
ValueError

When I put a breakpoint on:

if not current_lock.has_metadata:

You can see in the debugger that metadata has no values

Image

This is using both ravendb client and server version 7.2.0

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions