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

Address traceback on relation broken #383

Merged
merged 2 commits into from
Jan 23, 2025
Merged

Address traceback on relation broken #383

merged 2 commits into from
Jan 23, 2025

Conversation

sed-i
Copy link
Contributor

@sed-i sed-i commented Jan 22, 2025

Issue

When grafana-k8s is removed, we sometimes see

    data = self._charm.peers.data[self._charm.app].get(key, "")
AttributeError: 'NoneType' object has no attribute 'data'

Solution

Add a guard and return {} if the relation is None.

Fixes #365.

Context

Full traceback:

unit-graf-0: 18:46:29 WARNING unit.graf/0.grafana-dashboard-relation-broken   main(GrafanaCharm, use_juju_for_storage=True)
unit-graf-0: 18:46:29 ERROR unit.graf/0.juju-log grafana-dashboard:29: Uncaught exception while in charm code:
Traceback (most recent call last):
  File "./src/charm.py", line 1563, in <module>
    main(GrafanaCharm, use_juju_for_storage=True)
  File "/var/lib/juju/agents/unit-graf-0/charm/venv/ops/main.py", line 45, in main
    return _main.main(charm_class=charm_class, use_juju_for_storage=use_juju_for_storage)
  File "/var/lib/juju/agents/unit-graf-0/charm/venv/ops/_main.py", line 543, in main
    manager.run()
  File "/var/lib/juju/agents/unit-graf-0/charm/venv/ops/_main.py", line 529, in run
    self._emit()
  File "/var/lib/juju/agents/unit-graf-0/charm/venv/ops/_main.py", line 518, in _emit
    _emit_charm_event(self.charm, self.dispatcher.event_name, self._juju_context)
  File "/var/lib/juju/agents/unit-graf-0/charm/venv/ops/_main.py", line 134, in _emit_charm_event
    event_to_emit.emit(*args, **kwargs)
  File "/var/lib/juju/agents/unit-graf-0/charm/venv/ops/framework.py", line 347, in emit
    framework._emit(event)
  File "/var/lib/juju/agents/unit-graf-0/charm/venv/ops/framework.py", line 857, in _emit
    self._reemit(event_path)
  File "/var/lib/juju/agents/unit-graf-0/charm/venv/ops/framework.py", line 947, in _reemit
    custom_handler(event)
  File "/var/lib/juju/agents/unit-graf-0/charm/lib/charms/tempo_coordinator_k8s/v0/charm_tracing.py", line 735, in wrapped_function
    return callable(*args, **kwargs)  # type: ignore
  File "/var/lib/juju/agents/unit-graf-0/charm/lib/charms/grafana_k8s/v0/grafana_dashboard.py", line 1391, in _on_grafana_dashboard_relation_broken
    self._remove_all_dashboards_for_relation(event.relation)
  File "/var/lib/juju/agents/unit-graf-0/charm/lib/charms/tempo_coordinator_k8s/v0/charm_tracing.py", line 735, in wrapped_function
    return callable(*args, **kwargs)  # type: ignore
  File "/var/lib/juju/agents/unit-graf-0/charm/lib/charms/grafana_k8s/v0/grafana_dashboard.py", line 1525, in _remove_all_dashboards_for_relation
    if self._get_stored_dashboards(relation.id):
  File "/var/lib/juju/agents/unit-graf-0/charm/lib/charms/tempo_coordinator_k8s/v0/charm_tracing.py", line 735, in wrapped_function
    return callable(*args, **kwargs)  # type: ignore
  File "/var/lib/juju/agents/unit-graf-0/charm/lib/charms/grafana_k8s/v0/grafana_dashboard.py", line 1558, in _get_stored_dashboards
    return self.get_peer_data("dashboards").get(str(relation_id), {})
  File "/var/lib/juju/agents/unit-graf-0/charm/lib/charms/tempo_coordinator_k8s/v0/charm_tracing.py", line 735, in wrapped_function
    return callable(*args, **kwargs)  # type: ignore
  File "/var/lib/juju/agents/unit-graf-0/charm/lib/charms/grafana_k8s/v0/grafana_dashboard.py", line 1573, in get_peer_data
    data = self._charm.peers.data[self._charm.app].get(key, "")  # type: ignore[attr-defined]
AttributeError: 'NoneType' object has no attribute 'data'
unit-graf-0: 18:46:30 ERROR juju.worker.uniter.operation hook "grafana-dashboard-relation-broken" (via hook dispatching script: dispatch) failed: exit status 1

Testing Instructions

Upgrade Notes

@sed-i sed-i marked this pull request as ready for review January 22, 2025 22:38
@sed-i sed-i requested a review from a team as a code owner January 22, 2025 22:38
Copy link
Contributor

@lucabello lucabello left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, thanks for solving it :)

@sed-i sed-i merged commit 4abcf11 into main Jan 23, 2025
13 checks passed
@sed-i sed-i deleted the sed-i-patch-1 branch January 23, 2025 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Destroying model grafana remains in error state with hook failed: "grafana-dashboard-relation-broken"
2 participants