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

consistency checker gives false positives when working with copied objects #199

Closed
PietroPasotti opened this issue Sep 20, 2024 · 2 comments
Labels
bug Something isn't working ops-next To be done before the next ops release

Comments

@PietroPasotti
Copy link
Collaborator

This is a regression from scenario 6 (or perhaps it's good that it fails?)

MWE:

from ops import CharmBase
from scenario import Context
def test_relation_evt():
    ctx = Context(CharmBase, meta={"name": "mateusz",
                                   "requires": {"a": {"interface": "b"}}})
    rel = Relation("a", interface="b")
    rel_cpy = replace(rel, remote_app_data={"foo": "bar"})

    ctx.run(ctx.on.relation_changed(rel_cpy), State(relations={rel}))
    # scenario.errors.InconsistentScenarioError: Inconsistent scenario.
    # The following errors were found: cannot emit a_relation_changed because 
    # relation 1 is not in the state.

culprit is this line in the consistency checker:

if event.relation not in state.relations:
    ... <mark as inconsistent>

Proposed solution:

if event.relation.id not in [r.id for r in state.relations]:
    ...
@tonyandrewmeyer
Copy link
Collaborator

Proposed solution:

if event.relation.id not in [r.id for r in state.relations]:
    ...

I think this is the right solution - you can't have relations with the same ID even if they aren't the same Relation object.

Might need to check some of the others like containers as well?

@tonyandrewmeyer
Copy link
Collaborator

Moved to canonical/operator#1429

@tonyandrewmeyer tonyandrewmeyer closed this as not planned Won't fix, can't repro, duplicate, stale Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ops-next To be done before the next ops release
Projects
None yet
Development

No branches or pull requests

2 participants