Skip to content

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

Open
tonyandrewmeyer wants to merge 2 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 2 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
_JUJU_4_REMOVED_DATABAG_KEYS = ('private-address',)


def _strip_juju4_defaults(state: State, juju_version: str) -> None:

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.

Couldn't we use JujuVersion instead of custom logic to parse the version? (As in mocking.py)

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 feel like the value of JujuVersion is the properties, not parsing a very simple string. But sure, I can switch to that.

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.

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

2 participants