-
Notifications
You must be signed in to change notification settings - Fork 119
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: Document and validate settable status values in _ModelBackend.set_status #1354
chore: Document and validate settable status values in _ModelBackend.set_status #1354
Commits on Sep 3, 2024
-
Fix broken test of registering StatusBase subclass
Previously was catching AttributeError, which must have been raised historically for missing `name` attribute on StatusBase subclasses. This, combined with a `type: ignore` directive concealed that the `register_status` method does not exist -- the attempt to access it raises an AttributeError. The correct method is `register`, which raises a TypeError.
Configuration menu - View commit details
-
Copy full SHA for de6cede - Browse repository at this point
Copy the full SHA de6cedeView commit details -
A `type: ignore` directive hid that `status_set` was being called with the wrong argument types. The intention was to test that an error is raised on calling with a non-bool argument for `is_app`, however the status argument should be a string, and was instead a `StatusBase` class. The test would have still correctly errored out on the `is_app` argument before this error had an effect at testing time.
Configuration menu - View commit details
-
Copy full SHA for b586027 - Browse repository at this point
Copy the full SHA b586027View commit details -
Expose settable statuses in type hint of set_status
_ModelBackend.status_set's status argument was previously type hinted only as str. However, this argument can really only be one of four valid statuses that juju's set-status will accept. This commit documents this, and adjusts the definition of StatusBase to also type hint the six acceptable status names, as well as using these type hints across code that interacts with StatusBase and status_set.
Configuration menu - View commit details
-
Copy full SHA for c50dd47 - Browse repository at this point
Copy the full SHA c50dd47View commit details -
Validate status in status_set before calling status-set
Since we know the valid arguments for status, and expose them in type hints, and since ops already validates arguments here to some extent (is_app being a bool in status_set, status and message being strings in Application.status and Unit.status), let's check that status is valid in status_set and raise a ModelError immediately if not, rather than catching status-set's exit code and only then raising a ModelError.
Configuration menu - View commit details
-
Copy full SHA for f8e1596 - Browse repository at this point
Copy the full SHA f8e1596View commit details -
Validate type of message in set_status
Since _ModelBackend.set_status validates its status and is_app arguments, let's also validate the type of message, removing redundant checks from Application.status and cleaning up a fixme in Unit.status. Also add a test to cover this, analogous to the existing test for the type of is_app.
Configuration menu - View commit details
-
Copy full SHA for f9423de - Browse repository at this point
Copy the full SHA f9423deView commit details -
Revert change to signature of StatusBase.from_name
Since StatusBase.from_name is part of the public API, and is currently used in several charms, changing the type of the name argument from str to _StatusName will break users' tests. Furthermore, satisfying the type checker as to the contents of the strings used may be painful for users, leading to a proliferation of casts or `type: ignore`s. Therefore, the type or the name argument has been reverted to str.
Configuration menu - View commit details
-
Copy full SHA for 424b74d - Browse repository at this point
Copy the full SHA 424b74dView commit details
Commits on Sep 4, 2024
-
Unclear how to narrow type of value given that type checking doesn't excellently support properties with differing types for getter and setter, so sticking with a simple `cast` for now.
Configuration menu - View commit details
-
Copy full SHA for c295028 - Browse repository at this point
Copy the full SHA c295028View commit details -
Change object to object() in test cases
Either work, as we're just testing that the type not being bool or str raises an error, but bare object may raise eyebrows for readers.
Configuration menu - View commit details
-
Copy full SHA for ebe61a1 - Browse repository at this point
Copy the full SHA ebe61a1View commit details -
Raise InvalidStatusError instead of ModelError in status_set
InvalidStatusError is a subclass of ModelError, so it shouldn't break any user code, and anyway it doesn't look like people were setting invalid statuses since Juju would give them an error at runtime currently.
Configuration menu - View commit details
-
Copy full SHA for 3ad8459 - Browse repository at this point
Copy the full SHA 3ad8459View commit details
Commits on Sep 9, 2024
-
Configuration menu - View commit details
-
Copy full SHA for 0132af5 - Browse repository at this point
Copy the full SHA 0132af5View commit details
Commits on Sep 17, 2024
-
Document InvalidStatusError cases in add_status
Calling add_status with an ErrorStatus *will* eventually result in an InvalidStatusError. Calling add_status with an UnknownStatus *may* eventually result in an InvalidStatusError.
Configuration menu - View commit details
-
Copy full SHA for a92737e - Browse repository at this point
Copy the full SHA a92737eView commit details -
Configuration menu - View commit details
-
Copy full SHA for 8e17020 - Browse repository at this point
Copy the full SHA 8e17020View commit details -
Configuration menu - View commit details
-
Copy full SHA for aabb970 - Browse repository at this point
Copy the full SHA aabb970View commit details -
Configuration menu - View commit details
-
Copy full SHA for 435e539 - Browse repository at this point
Copy the full SHA 435e539View commit details -
Configuration menu - View commit details
-
Copy full SHA for f126853 - Browse repository at this point
Copy the full SHA f126853View commit details -
Configuration menu - View commit details
-
Copy full SHA for f2f57ee - Browse repository at this point
Copy the full SHA f2f57eeView commit details
Commits on Sep 18, 2024
-
Revert changes to docstring for CollectStatusEvent
The plan is to make using ErrorStatus and UnknownStatus here an error
Configuration menu - View commit details
-
Copy full SHA for fb95f48 - Browse repository at this point
Copy the full SHA fb95f48View commit details -
Configuration menu - View commit details
-
Copy full SHA for 2fe3bbd - Browse repository at this point
Copy the full SHA 2fe3bbdView commit details