Repository navigation
fix(opal-client): apply scoped data updates published through /scopes/{scope_id}/data/update - #981
Closed
folarinmartins wants to merge 1 commit into
Closed
folarinmartins wants to merge 1 commit into
folarinmartins wants to merge 1 commit into
Conversation
…/{scope_id}/data/update
A scoped client subscribes to "<scope_id>:data:<topic>", and the entries of
its scope's data sources config carry that form, so the initial load and the
periodic refresh apply. An update published through
POST /scopes/{scope_id}/data/update is delivered on the scoped topic
(ScopedServerSideTopicPublisher prefixes the scope), but its entries keep
"data:<topic>" (the endpoint rewrites entry.topics to f"data:{topic}" only).
DataUpdater then finds the entry's topics disjoint from its own and skips the
entry, so every pushed update to a scoped client is dropped silently and the
data only arrives with the next periodic refresh.
Normalise unscoped entry topics to the client's scope before the topic check.
Entries that already carry the scoped form, and clients in the default scope,
are unchanged; a topic of another scope still does not match.
Signed-off-by: Martins Folarin <folarin@engineer.com>
✅ Deploy Preview for opal-docs canceled.
|
Member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Data updates published to a scoped client through
POST /scopes/{scope_id}/data/updateare silently dropped by the client. The scoped client only receives its data through the initial load and the periodic refresh, so real-time push and broadcast never take effect for scopes.Why:
<scope_id>:data:<topic>(DataUpdater.__init__, "Namespacing the data topics for the specific scope").opal_server/scopes/api.py) rewritesentry.topics = [f"data:{topic}" ...]and publishes throughScopedServerSideTopicPublisher, which prefixes the scope on the published topic only (<scope_id>:data:<topic>).data:<topic>.DataUpdater._update_policy_dataskips it becauseset(entry.topics).isdisjoint(set(self._data_topics)).Observed (opal-server and opal-client 0.9.9; the same code is on
master):Publishing to topics: ['document-access:data:documents']for an update whose entry has'topics': ['data:documents'].OPAL_SCOPE_ID=document-access,OPAL_DATA_TOPICS=documents) never applies it.Fix
The topic check moves into a small
DataUpdater._entry_matches_data_topics(). For a non-default scope, it normalises an entry topic without the scope prefix to<scope_id>:<topic>before comparing.<scope_id>:data:<topic>): unchanged.data:<topic>): now match.other:data:<topic>): still doesn't match.defaultscope: unchanged; no rewriting.This is the smallest change that keeps both the config-entry form and the push-entry form valid. A server-side alternative would rewrite the entries' topics in the scope endpoint to the full scoped form. That needs the publisher to stop prefixing the scope again, and it changes the wire format for any other subscriber, so I kept the fix on the client side. Happy to move it if you prefer.
Tests
The new
packages/opal-client/opal_client/tests/data_updater_scoped_topics_test.pycovers:8 cases, all passing locally.