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

chore: make event_name mandatory in Framework #1538

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dimaqq
Copy link
Contributor

@dimaqq dimaqq commented Jan 24, 2025

I'm sure that the event name is always set (except some units tests)
Meanwhile we've got this signature: Framework.__init__(..., event_name: str|None, ...)
And therefore self._event_name is optional too.

This PR makes this mandatory.

Open question remaining: whether ops-scenario / ops version needs to be bumped to keep the two in sync.
That would be necessary if ops-scenario ships with harness code and ops is not.
(I don't recall if ops / ops['testing'] has reached that stage)

@benhoyt
Copy link
Collaborator

benhoyt commented Jan 26, 2025

What's the motivation for this change? Unless we have a very compelling reason, I don't think we should do it, as it's a breaking change and will actually break some charm tests (GitHub Actions exporter, Prometheus K8s, Sunbeam charms, and Traefik Route):

~/w/charm-analysis/.cache$ rg 'Framework\(' --sort=path -A5
github-actions-exporter-operator/tests/unit/test_charm.py
40:        self.harness._framework = ops.framework.Framework(
41-            self.harness._storage, self.harness._charm_dir, self.harness._meta, self.harness._model
42-        )
43-        self.harness._charm = None
44-        self.harness.update_config({"github_webhook_token": "foo"})
45-        self.harness.enable_hooks()
--
68:        self.harness._framework = ops.framework.Framework(
69-            self.harness._storage, self.harness._charm_dir, self.harness._meta, self.harness._model
70-        )
71-        self.harness._charm = None
72-        self.harness.update_config({"github_webhook_token": ""})
73-        self.harness.enable_hooks()
--
118:        self.harness._framework = ops.framework.Framework(
119-            self.harness._storage, self.harness._charm_dir, self.harness._meta, self.harness._model
120-        )
121-        self.harness._charm = None
122-        new_webhook_token = token_hex(16)
123-        self.harness.update_config({"github_webhook_token": new_webhook_token})

prometheus-k8s-operator/tests/unit/test_remote_write.py
292:            self.harness._framework = framework.Framework(
293-                self.harness._storage,
294-                self.harness._charm_dir,
295-                self.harness._meta,
296-                self.harness._model,
297-            )

sunbeam-charms/ops-sunbeam/ops_sunbeam/test_utils.py
822:    harness._framework = framework.Framework(
823-        ops.storage.SQLiteStorage(":memory:"),
824-        harness._charm_dir,
825-        harness._meta,
826-        harness._model,
827-    )

traefik-route-k8s-operator/tests/unit/conftest.py
79:    harness._framework = framework.Framework(
80-        harness._storage, harness._charm_dir, harness._meta, harness._model
81-    )
82-
83-    harness._charm = None
84-    harness.begin()

@dimaqq
Copy link
Contributor Author

dimaqq commented Jan 27, 2025

Oh, I didn't realise that charm tests instantiated the ops.Framework directly, I thought that surely they used the fake framework from Harness or something like that.

Given this, I guess the proposed change is a no-go.

Maybe let's discuss if we can get rid of this nit somehow... (docs? long deprecation period? a default like event_name="he-be-dragons", smth else?).

I consider it a nit because a usable Framework, that is a framework that can call the user handlers for events, must have an event associated with it, or an event set to call handlers.

@dimaqq dimaqq mentioned this pull request Jan 27, 2025
42 tasks
@dimaqq dimaqq marked this pull request as draft January 27, 2025 06:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants