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

[ISSUE-42;ISSUE-43] is_resource_created improvements and fixes #44

Merged

Conversation

deusebio
Copy link
Contributor

Addressing #42 and #43

Copy link
Contributor

@welpaolo welpaolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This improvement looks really good. I will also fix the function fetch_relation_data and change the line 504 of the data_interfaces in this way:

if f"{self.relation_name}-relation-broken" in os.environ.get("JUJU_HOOK_NAME", ""):

This will avoid the raise of the runtime exception if the relation-broken event is not related to the database.

Copy link
Contributor

@welpaolo welpaolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@deusebio deusebio merged commit 18f73f1 into canonical:main Feb 16, 2023
@deusebio deusebio deleted the wip-issue-42-is-resource-no-relation branch February 16, 2023 17:11
@beliaev-maksim
Copy link
Member

@deusebio @welpaolo @delgod
so, you removed in this PR check for relation broken. But then it is not really clear what user did wrong. eg without reading docstring of the function you will never know

could this be improved?

This will avoid the raise of the runtime exception if the relation-broken event is not related to the database.

was not check checking the name of the database relation to ensure it is only related to database relations?

@deusebio
Copy link
Contributor Author

deusebio commented Jun 29, 2023

I'm not sure I fully understand what you mean. IIRC, here the issue is that there may exist multiple relations under the same relation name, and fetch_relation_data fetches the databags for all of them, indexed by the relation id.

Now, previously in the relation_broken_event, we were raising an exception in any relation broken event, which it is a bit too general/broad, as people may still want to access the data for the relations other than the one tearing down. Indeed, this was a use case that some people stumbled upon (OSM team if I recall correctly). I remembered that there was also a somewhat inconsistent behaviour for accessing relation data in integration tests vs unittests (see MM thread here), but this might be a different story.

So, here we basically just fetch the data that can be fetched. If the databag of the relation broken is not available, the dictionary would just NOT have the corresponding relation id key rather than raising an exception. I don't think the users would do anything wrong to use fetch_relation_data in relation_broken_event. Just there may not be some data there. Also, If they try to self.fetch_relation_data()[relation_id] for relations that had been removed, they will get an exception anyway.

@beliaev-maksim
Copy link
Member

@deusebio
knowing the context it makes sense :)
however, during execution it might be confusing for users :)

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.

4 participants