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
This is using both ravendb client and server version 7.2.0
When creating a
Compare Exhange Itemand attaching metadata such as:The
Compare Exchange Itemis 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 aValueErrorbecausecurrent_lock.metadata["@created-at"]does not exist in theCompareExchangeValue, nor does any metadata according to the CompareExchangeValue:Raises:
When I put a breakpoint on:
You can see in the debugger that metadata has no values
This is using both ravendb client and server version 7.2.0