From 5e6d7e4768e6475a478c21c11321f805a668da24 Mon Sep 17 00:00:00 2001 From: Matt Kafonek Date: Mon, 8 May 2023 15:33:55 -0400 Subject: [PATCH] logic fix for squashing deltas on file subscribe reply (#106) --- CHANGELOG.md | 5 +++++ origami/rtu_client/client.py | 10 ++++++++-- pyproject.toml | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a6410be..e859fb3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +## [0.0.26] - 2023-05-08 +### Fixed +- Logic error in squashing "deltas-to-apply" during file subscribe reply +- Return value from `RTUManager.register_callback` to support unregistering callbacks (one-shot callbacks) + ## [0.0.25] - 2023-05-05 ## Added - Moved `RTUClient` and `NotebookBuilder` (with Pydantic models for a Notebook) into `origami`. diff --git a/origami/rtu_client/client.py b/origami/rtu_client/client.py index 514793e..887a0f0 100644 --- a/origami/rtu_client/client.py +++ b/origami/rtu_client/client.py @@ -135,7 +135,7 @@ def predicate_fn(topic: Literal[""], msg: rtu.GenericRTUReply): return True return False - self.manager.register_callback(fn, on_predicate=predicate_fn) + return self.manager.register_callback(fn, on_predicate=predicate_fn) def register_delta_callback(self, fn: Callable, delta_type: str = "*", delta_action: str = "*"): """ @@ -330,7 +330,13 @@ async def queue_or_apply_delta(self, delta: deltas.FileDelta): If it is not a match, we may have received out of order deltas and we queue it to be replayed later """ - if delta.parent_delta_id == self.builder.last_applied_delta_id: + if self.builder.last_applied_delta_id is None: + # We need this for situations where we've downloaded the seed notebook and gotten deltas + # to apply from file subscribe reply, but do not have information about what the first + # delta in that deltas-to-apply list is. + await self.apply_delta(delta=delta) + + elif delta.parent_delta_id == self.builder.last_applied_delta_id: # For logging related to applying delta, override .pre_apply_delta await self.apply_delta(delta=delta) await self.replay_unapplied_deltas() diff --git a/pyproject.toml b/pyproject.toml index ad2a91a..dc5c9e5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ [tool.poetry] name = "noteable-origami" -version = "0.0.25" +version = "0.0.26" description = "The Noteable API interface" authors = ["Matt Seal "] maintainers = ["Matt Seal "]