From 47343772a82e43673c86fb09a1dc3e1f7198ad9f Mon Sep 17 00:00:00 2001 From: Subhash Bhushan Date: Thu, 17 Feb 2022 18:14:58 -0800 Subject: [PATCH] Miscellaneous bug fixes for message and versioning compatibility --- src/protean/adapters/broker/celery.py | 2 +- src/protean/adapters/repository/elasticsearch.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/protean/adapters/broker/celery.py b/src/protean/adapters/broker/celery.py index 49f60cb6..8391b4c7 100644 --- a/src/protean/adapters/broker/celery.py +++ b/src/protean/adapters/broker/celery.py @@ -96,7 +96,7 @@ def register(self, initiator_cls, consumer_cls): def publish(self, message: Message) -> None: event_cls = fetch_element_cls_from_registry( - message["name"], (DomainObjects.EVENT,) + message.type, (DomainObjects.EVENT,) ) for subscriber in self._subscribers[fully_qualified_name(event_cls)]: if self.conn_info["IS_ASYNC"]: diff --git a/src/protean/adapters/repository/elasticsearch.py b/src/protean/adapters/repository/elasticsearch.py index 2f3acc99..e9f0cbeb 100644 --- a/src/protean/adapters/repository/elasticsearch.py +++ b/src/protean/adapters/repository/elasticsearch.py @@ -91,8 +91,9 @@ def to_entity(cls, item: "ElasticsearchModel"): id_field_name = id_field(cls.meta_.entity_cls).field_name item_dict[id_field_name] = identifier - # Set version from document meta - item_dict["_version"] = item.meta.version + # Set version from document meta, only if `_version` attr is present + if hasattr(cls.meta_.entity_cls, "_version"): + item_dict["_version"] = item.meta.version entity_obj = cls.meta_.entity_cls(item_dict)