Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Minor improvements #31
Conversation
| @@ -41,14 +41,14 @@ def status(self): | ||
| """Get the application status, as set by the charm's leader. | ||
| """ | ||
| - return self.data['status']['current'] | ||
| + return self.__getattr__('status')['current'] |
tvansteenburgh
Dec 9, 2016
Member
Forgive my density, can you explain the benefit of this change in more detail?
johnsca
Dec 9, 2016
Member
np, probably should have commented that. The intention is to have it run though the checks in ModelEntity.__getattr__ so that we get a more useful error if accessed on a dead entity (rather than NoneType is not subscriptable).
petevg
Dec 12, 2016
•
Collaborator
It's a little odd to me to see you call self.__getattr__ rather than getattr(self, ..., but it's not that big of a deal. If the class is always guaranteed to have a status, I can see dropping it, per @tvansteenburgh
tvansteenburgh
Dec 12, 2016
Member
self.status is the same as self.data['status'] (because of the __getattr__ that we have on ModelEntity. But that won't work for hyphenated names, like 'agent-status'.
My main complaints with this is that 1) it makes my eyes bleed 2) it's hard to understand why it's there unless you already know (difficult to maintain) and 3) we (or someone else) will forget to use this technique in the future.
I'd like to see us come up with a cleaner way to achieve the same result if possible.
johnsca
Dec 12, 2016
Member
There was a naming conflict with self.status in one of the methods (which also caused an issue with using getattr()), and the others included hyphenation. I'll make something cleaner because I agree that it sucks.
|
This looks a lot nicer :-) LGTM. |
|
This addresses two of my issues nicely. But...
I would prefer to just do the None check in the I wonder if we should add a Sorry, I'm really not trying to be difficult here, I just don't feel like this is quite right yet. Definitely open to more discussion/ideas. |
|
@tvansteenburgh Updated. |
| @property | ||
| def agent_status_since(self): | ||
| """Get the time when the `agent_status` was last updated. | ||
| """ | ||
| - return parse_date(self.data['agent-status']['since']) | ||
| + return parse_date(self.self_data['agent-status']['since']) |
johnsca commentedDec 9, 2016