Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SceneQueryRunner: Meaningful cloning #652

Merged
merged 1 commit into from
Mar 21, 2024
Merged

SceneQueryRunner: Meaningful cloning #652

merged 1 commit into from
Mar 21, 2024

Conversation

dprokop
Copy link
Member

@dprokop dprokop commented Mar 20, 2024

Fixes a bug I have discovered in core Grafana: grafana/grafana#84818

The problem is that in the PanelEditor in core Grafana we are using the cloned version of the data provider. When it's activated, it uses data layers results (via ReplaySubject in the layer) causing the onLayersReceived being called. But, this function depends on SQR's private _resultAnnotations propert, that is not cloned given it's a instance property, not part of the object state. Hence we are losing the query-provided annotations.

However, it's actually reflecting a state of an object as it holds annotation results that might have been part of a query response. So, it is technically SQR's state.

There are alternatives to this approach:

  1. Move _resultAnnotations / _layerAnnotations instance properties into SQR's state. This would be a bigger refactor. Also leaks the implementation details to a public state. This is next scenario when SceneObject private state would beuseful :)
  2. Make _resultAnnotations / _layerAnnotations public properties or provide setters to allow setting externally. Again, leaking internals. Also would delegate the complexity of remembering about setting those when cloning to the consumer. Sounds like a bad idea.

So I consider the proposed approach quite elegant, as it does not yield an API change while providing the required functionality.

@dprokop dprokop added type/bug Something isn't working patch Increment the patch version when merged release Create a release when this pr is merged labels Mar 20, 2024
@dprokop dprokop self-assigned this Mar 20, 2024
@dprokop dprokop merged commit 9317740 into main Mar 21, 2024
3 checks passed
@dprokop dprokop deleted the sqr-meaningful-clone branch March 21, 2024 09:18
@grafanabot
Copy link
Contributor

🚀 PR was released in v4.0.1 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
patch Increment the patch version when merged release Create a release when this pr is merged released type/bug Something isn't working
Projects
Status: 🚀 Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants