Skip to content

fix: make create-replication action fail cleanly without async-replication relation#1676

Open
SAY-5 wants to merge 2 commits intocanonical:mainfrom
SAY-5:fix/1675-create-replication-no-relation
Open

fix: make create-replication action fail cleanly without async-replication relation#1676
SAY-5 wants to merge 2 commits intocanonical:mainfrom
SAY-5:fix/1675-create-replication-no-relation

Conversation

@SAY-5
Copy link
Copy Markdown
Contributor

@SAY-5 SAY-5 commented May 5, 2026

Issue

Closes #1675. Running juju run postgresql/<unit> create-replication name=default on a unit with no async-replication relation crashed with AttributeError: 'NoneType' object has no attribute 'name' because _on_create_replication dereferenced self._relation.name before checking that the relation existed.

Solution

Guard self._relation for None and call event.fail with a clear message instructing the operator to create the offer and relate the clusters first. Added a regression test exercising the missing-relation path.

Checklist

  • I have added or updated any relevant documentation.
  • I have cleaned any remaining cloud resources from my accounts.

…ation relation

Signed-off-by: SAY-5 <saiasish.cnp@gmail.com>
@SAY-5 SAY-5 requested a review from a team as a code owner May 5, 2026 10:17
@SAY-5 SAY-5 requested review from carlcsaposs-canonical, dragomirp, juju-charm-bot, marceloneppel and taurus-forever and removed request for a team May 5, 2026 10:17
@marceloneppel marceloneppel added the bug Something isn't working as expected label May 5, 2026
Copy link
Copy Markdown
Contributor

@taurus-forever taurus-forever left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution!

At least unit tests are unhappy here:

tests/unit/test_async_replication.py::test__configure_standby_cluster[True] FAILED
tests/unit/test_async_replication.py::test__configure_standby_cluster[False] FAILED
tests/unit/test_async_replication.py::test_handle_replication_change[True] FAILED
tests/unit/test_async_replication.py::test_handle_replication_change[False] FAILED
tests/unit/test_async_replication.py::test_handle_forceful_promotion[True] FAILED
tests/unit/test_async_replication.py::test_handle_forceful_promotion[False] FAILED

Please adopt. Please also sign commits and SLA agreement (new gmail email used?).

Signed-off-by: SAY-5 <saiasish.cnp@gmail.com>
@SAY-5
Copy link
Copy Markdown
Contributor Author

SAY-5 commented May 5, 2026

Fixed — the regression test set type(relation)._relation = PropertyMock(...) directly, which mutated the class globally and leaked into later tests. Wrapped it in a patch.object context manager so the descriptor is restored on exit. All 32 tests in test_async_replication.py pass locally now. CI should re-run.

Copy link
Copy Markdown
Member

@marceloneppel marceloneppel left a comment

Choose a reason for hiding this comment

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

Thanks for the fixes, @SAY-5! Did you check the CLA?

@SAY-5
Copy link
Copy Markdown
Contributor Author

SAY-5 commented May 6, 2026

Yes — CLA signing is on my checklist. I'll get that signed shortly so this can land.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

create-replication action crashes with AttributeError when async-replication relation is not established

3 participants