Skip to content

fix: don't include private-address in default testing.Relation databags on Juju 4#2618

Open
tonyandrewmeyer wants to merge 3 commits into
canonical:mainfrom
tonyandrewmeyer:rainy/2185-no-private-address-juju-4
Open

fix: don't include private-address in default testing.Relation databags on Juju 4#2618
tonyandrewmeyer wants to merge 3 commits into
canonical:mainfrom
tonyandrewmeyer:rainy/2185-no-private-address-juju-4

Conversation

@tonyandrewmeyer

@tonyandrewmeyer tonyandrewmeyer commented Jul 5, 2026

Copy link
Copy Markdown
Collaborator

At exec time, remove the private-address key from the databags, if it's set to our default value and the mock Juju version is 4+.

I don't love this solution, since we're editing the State after the user has finished with it, but it's only when we have the Context that the version is available, so there doesn't seem to be a backwards-compatible alternative. It would probably be better if the runtime injected the automated keys and they weren't there when the user had the State, or maybe if you had to provide a version when getting a fresh Relation, but we can't do either of those in 8.x. This change at least gives the Juju behaviour, even if it's a bit quirky.

Regarding the comment in the issue, what I am proposing is that we do this workaround so that the Scenario 8.x behaviour matches Juju 3 and 4, and we do something more elaborate and backwards incompatible in 9.0 (I added to the list in #2350). We could instead reject this change and opt in to new behaviour with a env flag or similar, but I feel even if we do that we would want this change so that the default behaviour is the Juju one.

Fixes #2185

@tonyandrewmeyer tonyandrewmeyer marked this pull request as ready for review July 6, 2026 00:10

@dwilding dwilding left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Main comment is about (lack of) JujuVersion

Comment thread testing/tests/test_e2e/test_relations.py
Comment thread testing/src/scenario/state.py
if major < 4:
return
for relation in state.relations:
for databag in relation._databags:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

My review agent tells me that this would remove private-address from local_app_data and remote_app_data - if someone has set private-address to the default value in those databags. I feel like we're safe to assume nobody would ever do that... What do you think?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I did wonder about this. There's some chance a charm could do this to make their Juju 4 databag look like a Juju 3 one. I'd argue that it's not a good idea, but it's not impossible.

If someone does that their tests would break and they wouldn't be able to get around that.

The only ideas I have for avoiding that are ugly (like a special object we set instead, which we can recognise later, but pretends to be the normal one when people work with their state).

I think this comes down to a decision about whether we want to have a fix in Scenario 8 so the Juju 4 behaviour is surfaced, only have a fix with something opt-in (where we could do this more cleanly), or only fix it in 9.0 (definitely could do it clean, but people's tests may need updates). Or someone comes up with an idea I haven't thought of, of course.

I lean towards what's in the PR, but I can definitely be convinced we should go another way.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm OK with what's in this PR. My knowledge is a bit limited here, so no objection if you and James decide to go in a different direction.

@james-garner-canonical

Copy link
Copy Markdown
Contributor
  • How breaky is this PR?
  • I'd be curious to see just how breaky changing the behaviour in the desired way instead would be: changing the default factories to provide empty dicts and populating the correct Juju-inserted keys at exec time (+/- having the Juju-inserted keys flow through to the output state).

I think it would be great to quantify the difference in breaky-ness so we can make an informed choice about whether this is the right fix for now.

PS: An idea for making this PR's approach safer -- track if the default factory was called with a private marker on the relation object, and only replace in that case. But maybe that falls apart as soon as we hit dataclasses.replace ...

@tonyandrewmeyer

Copy link
Copy Markdown
Collaborator Author
  • How breaky is this PR?

In terms of running Hyrum? Or in my opinion given what code changes?

  • I'd be curious to see just how breaky changing the behaviour in the desired way instead would be: changing the default factories to provide empty dicts and populating the correct Juju-inserted keys at exec time (+/- having the Juju-inserted keys flow through to the output state).

This feels objectively more break-y to me, because it impacts Juju 3 as well as Juju 4, and also the keys that are still injected in both. But I could implement it and run it over the fleet tests to get actual numbers.

PS: An idea for making this PR's approach safer -- track if the default factory was called with a private marker on the relation object, and only replace in that case. But maybe that falls apart as soon as we hit dataclasses.replace ...

Yeah, that sort of thing (as well as using a dict-subclass or something) is the kind of thing I was thinking of when I was saying there are "ugly" solutions. My preference would be to avoid those, and go with a clean solution (that I can't think of), the one in this PR, or an opt-in fix that becomes the default in 9.0.

@james-garner-canonical

Copy link
Copy Markdown
Contributor
  • How breaky is this PR?

In terms of running Hyrum? Or in my opinion given what code changes?

  • I'd be curious to see just how breaky changing the behaviour in the desired way instead would be: changing the default factories to provide empty dicts and populating the correct Juju-inserted keys at exec time (+/- having the Juju-inserted keys flow through to the output state).

This feels objectively more break-y to me, because it impacts Juju 3 as well as Juju 4, and also the keys that are still injected in both. But I could implement it and run it over the fleet tests to get actual numbers.

You're probably right, but with how cheap implementation is I'd love to see the Hyrum numbers for the different approaches.

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.

Don't include private-address in the default Scenario database when mocking Juju 4

3 participants