Resolve Python raw deletes by schema alias

This commit is contained in:
Meta Vens 2026-06-27 22:13:28 +01:00
commit d9ffdd77a4
4 changed files with 94 additions and 6 deletions

View file

@ -848,8 +848,7 @@ class CultMeshDatabase:
def _document_for_schema(self, schema_id: str) -> DocumentDefinition[Any] | None:
for document in self.documents:
entry = document.catalog_entry()
if schema_id == entry.schema_id or schema_id in entry.compatible_schema_ids:
if _document_matches_schema_id(document, schema_id):
return document
return None
@ -931,7 +930,8 @@ class CultMeshDatabase:
if document is None:
continue
record_key = str(delete.get("recordKey"))
previous[(schema_id, record_key)] = self.cache.get(document, record_key)
resolved_schema_id = document.catalog_entry().schema_id
previous[(resolved_schema_id, record_key)] = self.cache.get(document, record_key)
return previous
def _previous_values_for_raw_records(self, records: Any) -> dict[tuple[str, str], Any]:
@ -979,6 +979,15 @@ def _infer_schema_name(schema_id: str) -> str | None:
return schema_id[:marker] if version.isdigit() else None
def _document_matches_schema_id(document: DocumentDefinition[Any], schema_id: str) -> bool:
entry = document.catalog_entry()
if schema_id in (entry.schema_id, entry.schema_name, entry.schema_version):
return True
if schema_id in entry.compatible_schema_ids:
return True
return _infer_schema_name(schema_id) == entry.schema_name
def create_node(
cache_path: str | Path | None = None,
*,

View file

@ -382,7 +382,7 @@ class CultMeshLocalServer:
message_id=str(message.get("messageId") or ""),
code="unregistered_document_delete",
)]
return self._database_delete_notifications(message, subscriptions)
return self._database_delete_notifications(message, subscriptions, resolved_schema_id=change.schema_id)
def _database_change_notifications(
self,
@ -415,13 +415,19 @@ class CultMeshLocalServer:
self,
message: dict[str, Any],
subscriptions: dict[str, _DatabaseSubscription],
*,
resolved_schema_id: str | None = None,
) -> list[dict[str, Any]]:
schema_id = str(message.get("schemaId") or "")
record_key = str(message.get("recordKey") or "")
notifications = []
document = {"schemaId": schema_id, "recordKey": record_key}
for subscription in subscriptions.values():
if not self._subscription_matches_document(subscription, document):
if not self._subscription_matches_document(
subscription,
document,
resolved_schema_id=resolved_schema_id,
):
continue
message_id = message.get("messageId") or record_key or "change"
notifications.append({
@ -678,6 +684,7 @@ def _schema_document_map(documents: list[Any]) -> dict[str, Any]:
entry = document.catalog_entry()
mapped[entry.schema_id] = document
mapped[entry.schema_name] = document
mapped[entry.schema_version] = document
for compatible_schema_id in entry.compatible_schema_ids:
mapped[compatible_schema_id] = document
return mapped

View file

@ -24,6 +24,7 @@ def schema_document_map(documents: Iterable[DocumentDefinition[Any]]) -> dict[st
catalog_entry = document.catalog_entry()
mapped[catalog_entry.schema_id] = document
mapped[catalog_entry.schema_name] = document
mapped[catalog_entry.schema_version] = document
for compatible_schema_id in catalog_entry.compatible_schema_ids:
mapped[compatible_schema_id] = document
return mapped
@ -140,8 +141,9 @@ def apply_shard_log_response(
if schema_id not in documents_by_schema_id:
continue
document = documents_by_schema_id[schema_id]
resolved_schema_id = document.catalog_entry().schema_id
cache.delete(document, record_key)
applied.append(CultNetAppliedRecord(schema_id, record_key, "removed", None))
applied.append(CultNetAppliedRecord(resolved_schema_id, record_key, "removed", None))
return applied