[charms.reactive] http relation.available gets called on upgrade-charm hook, gives error.
Cory Johns
cory.johns at canonical.com
Mon Oct 26 17:21:33 UTC 2015
Merlijn,
You'll note that the docs for auto_accessors
<https://pythonhosted.org/charms.reactive/charms.reactive.relations.html#charms.reactive.relations.RelationBase.auto_accessors>
says that it's not a good idea to use with non-GLOBAL scoped relations, for
this very reason. The problem is that there's no way which unit's or
service's host and port you are trying to get, since there could be many.
If it's true that there should only be a single connected service on this
relation, then you should switch it to GLOBAL scope to indicate that.
Otherwise, you need to be handling the possibility of multiple connected
units explicitly.
See
https://github.com/johnsca/juju-relation-mysql/blob/master/provides.py#L74
for an example of how an interface layer should handle multiple
conversations.
On Mon, Oct 26, 2015 at 5:58 AM, Merlijn Sebrechts <
merlijn.sebrechts at gmail.com> wrote:
> Hi all
>
>
> I have the following piece of code that reacts to the
> httprelation.available hook (called rest2jfed in this case):
>
>
> @when('rest2jfed.available')
> def setup_rest2jfed(rest2jfed):
> hostname = rest2jfed.host()
> port = rest2jfed.port()
> # Do some stuff with hostname and port
> hookenv.status_set('active', 'Ready')
>
>
> This piece of code gets called on the upgrade-charm hook. This throws an
> error because there is not a relationship context.
>
> File "lib/charms/reactive/relations.py", line 88, in __accessor
> return self.get_remote(field)
> File "lib/charms/reactive/relations.py", line 308, in get_remote
> return self.conversation(scope).get_remote(key, default)
> File "lib/charms/reactive/relations.py", line 255, in conversation
> raise ValueError('Unable to determine default scope: no current hook
> or global scope')
>
> Am I using this relation wrong or is this a bug?
>
>
>
> Kind regards
> Merlijn
>
> --
> Juju mailing list
> Juju at lists.ubuntu.com
> Modify settings or unsubscribe at:
> https://lists.ubuntu.com/mailman/listinfo/juju
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/juju/attachments/20151026/9248397a/attachment.html>
More information about the Juju
mailing list