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
Set Relation.app via JUJU_REMOTE_APP or "relation-list --app" if no units #475
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We discussed this in person, but it isn't complete as is.
The problem is that it assumes JUJU_REMOTE_APP is valid for all relations, while it is only valid for the current JUJU_RELATION_ID.
However, if we tracked those two pieces, we probably have a reasonable fix for #175 that would be backwards compatible with juju 2.7 and 2.8. And while it doesn't solve the overall modeling problem it does, at least, fix a common error case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is certainly going in the right direction. A few small changes.
We also are missing the direct tests of the _ModelBackend (when the env var is set, when it is set but matches a different relation_id, etc)
@jameinel Ian pointed out that |
ops/model.py
Outdated
return self._run('relation-list', '-r', str(relation_id), '--app', | ||
return_output=True, use_json=True) | ||
except ModelError as e: | ||
if 'relation not found' in str(e): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the frequency of this pattern:
except ModelError as e:
if 'relation not found' in str(e):
raise RelationNotFoundError() from e
raise
(Which happens 3 times quickly together.)
I do wonder about trying to find commonality there, but it is a relatively short snippet. (it just happens to be easy to typo 'relation no found' and then never triggers but you don't notice.
I'm also not 100% sure what should happen if you ask for a remote application name but the relation doesn't exist. Is 'return None' the right answer here? The other _ModelBackend commands actually raise an exception, though at a higher level they do suppress the error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a _is_relation_not_found
helper to unify and avoid typos.
Regarding returning None
here -- it seemed right for this function (and is documented and used as such). Given that it's an internal function, I think it's fine, and we can always iterate later if we want to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates
This is canonical#175 and manifests itself as issues like https://bugs.launchpad.net/juju/+bug/1914415
c161b9d
to
13907a6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thank-you
Charm errors were happening because we were setting
Relation.app
from the app of the first unit, but if an event was fired before any units had started up (this happens onrelation-created
, for example), theapp
field was None and this caused aKeyError
later when charms did things likeevent.relation.data[event.app]
(event.app
wasNone
).The code still starts with the current method (first app of the units), but in the case when that doesn't work because there are no units, we fall back to:
JUJU_RELATION_ID
), then useJUJU_REMOTE_APP
as the remote app name.relation-list --app
to fetch the remote app name (--app
was introduced in Juju 2.8.1).Fixes #175 and manifests itself as issues like https://bugs.launchpad.net/juju/+bug/1914415