From c0578ff0f68c90c822e1a15bb79916242a9a8204 Mon Sep 17 00:00:00 2001 From: Carl Csaposs Date: Wed, 26 Jun 2024 13:31:55 +0200 Subject: [PATCH 1/4] Update ops to v2.14 Workaround for breaking change in ops 2.10: https://github.com/canonical/operator/pull/1091#issuecomment-1888644075 Workaround may break during deferred ops events or collect status ops events (https://github.com/canonical/operator/pull/1091#issuecomment-2191460188) --- poetry.lock | 34 +++++++----------------------- pyproject.toml | 6 +++--- src/abstract_charm.py | 2 +- src/relations/database_provides.py | 31 +++++++++++++++++++-------- src/relations/database_requires.py | 10 ++++++++- 5 files changed, 43 insertions(+), 40 deletions(-) diff --git a/poetry.lock b/poetry.lock index c3e5a1480..3ee2b448a 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand. [[package]] name = "allure-pytest" @@ -1119,16 +1119,6 @@ files = [ {file = "MarkupSafe-2.1.3-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:5bbe06f8eeafd38e5d0a4894ffec89378b6c6a625ff57e3028921f8ff59318ac"}, {file = "MarkupSafe-2.1.3-cp311-cp311-win32.whl", hash = "sha256:dd15ff04ffd7e05ffcb7fe79f1b98041b8ea30ae9234aed2a9168b5797c3effb"}, {file = "MarkupSafe-2.1.3-cp311-cp311-win_amd64.whl", hash = "sha256:134da1eca9ec0ae528110ccc9e48041e0828d79f24121a1a146161103c76e686"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-macosx_10_9_universal2.whl", hash = "sha256:f698de3fd0c4e6972b92290a45bd9b1536bffe8c6759c62471efaa8acb4c37bc"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:aa57bd9cf8ae831a362185ee444e15a93ecb2e344c8e52e4d721ea3ab6ef1823"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ffcc3f7c66b5f5b7931a5aa68fc9cecc51e685ef90282f4a82f0f5e9b704ad11"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:47d4f1c5f80fc62fdd7777d0d40a2e9dda0a05883ab11374334f6c4de38adffd"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:1f67c7038d560d92149c060157d623c542173016c4babc0c1913cca0564b9939"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:9aad3c1755095ce347e26488214ef77e0485a3c34a50c5a5e2471dff60b9dd9c"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:14ff806850827afd6b07a5f32bd917fb7f45b046ba40c57abdb636674a8b559c"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8f9293864fe09b8149f0cc42ce56e3f0e54de883a9de90cd427f191c346eb2e1"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-win32.whl", hash = "sha256:715d3562f79d540f251b99ebd6d8baa547118974341db04f5ad06d5ea3eb8007"}, - {file = "MarkupSafe-2.1.3-cp312-cp312-win_amd64.whl", hash = "sha256:1b8dd8c3fd14349433c79fa8abeb573a55fc0fdd769133baac1f5e07abf54aeb"}, {file = "MarkupSafe-2.1.3-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:8e254ae696c88d98da6555f5ace2279cf7cd5b3f52be2b5cf97feafe883b58d2"}, {file = "MarkupSafe-2.1.3-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:cb0932dc158471523c9637e807d9bfb93e06a95cbf010f1a38b98623b929ef2b"}, {file = "MarkupSafe-2.1.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9402b03f1a1b4dc4c19845e5c749e3ab82d5078d16a2a4c2cd2df62d57bb0707"}, @@ -1352,19 +1342,22 @@ files = [ [[package]] name = "ops" -version = "2.6.0" +version = "2.14.0" description = "The Python library behind great charms" optional = false python-versions = ">=3.8" files = [ - {file = "ops-2.6.0-py3-none-any.whl", hash = "sha256:b8ce352df4d17de483173dd2f8caf397e89585212d73b4d466b541b1ad3b8966"}, - {file = "ops-2.6.0.tar.gz", hash = "sha256:387d5f5bd004b865f575ea4e25ca298bdca05b2b2beb2c51f203d5856c460cf6"}, + {file = "ops-2.14.0-py3-none-any.whl", hash = "sha256:b1d7b03f87fa154bf0f2c0d688cb117d5ad8a2830966498fc66ba46987ae375d"}, + {file = "ops-2.14.0.tar.gz", hash = "sha256:23d64b5e9433176f171895fbe3f21ad1963eaa073a20ae01f0f38171c688eb1a"}, ] [package.dependencies] PyYAML = "==6.*" websocket-client = "==1.*" +[package.extras] +docs = ["canonical-sphinx-extensions", "furo", "linkify-it-py", "myst-parser", "pyspelling", "sphinx (==6.2.1)", "sphinx-autobuild", "sphinx-copybutton", "sphinx-design", "sphinx-notfound-page", "sphinx-tabs", "sphinxcontrib-jquery", "sphinxext-opengraph"] + [[package]] name = "ops-scenario" version = "5.6.2" @@ -2017,7 +2010,6 @@ files = [ {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:69b023b2b4daa7548bcfbd4aa3da05b3a74b772db9e23b982788168117739938"}, {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:81e0b275a9ecc9c0c0c07b4b90ba548307583c125f54d5b6946cfee6360c733d"}, {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ba336e390cd8e4d1739f42dfe9bb83a3cc2e80f567d8805e11b46f4a943f5515"}, - {file = "PyYAML-6.0.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:326c013efe8048858a6d312ddd31d56e468118ad4cdeda36c719bf5bb6192290"}, {file = "PyYAML-6.0.1-cp310-cp310-win32.whl", hash = "sha256:bd4af7373a854424dabd882decdc5579653d7868b8fb26dc7d0e99f823aa5924"}, {file = "PyYAML-6.0.1-cp310-cp310-win_amd64.whl", hash = "sha256:fd1592b3fdf65fff2ad0004b5e363300ef59ced41c2e6b3a99d4089fa8c5435d"}, {file = "PyYAML-6.0.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:6965a7bc3cf88e5a1c3bd2e0b5c22f8d677dc88a455344035f03399034eb3007"}, @@ -2025,16 +2017,8 @@ files = [ {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:42f8152b8dbc4fe7d96729ec2b99c7097d656dc1213a3229ca5383f973a5ed6d"}, {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:062582fca9fabdd2c8b54a3ef1c978d786e0f6b3a1510e0ac93ef59e0ddae2bc"}, {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d2b04aac4d386b172d5b9692e2d2da8de7bfb6c387fa4f801fbf6fb2e6ba4673"}, - {file = "PyYAML-6.0.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:e7d73685e87afe9f3b36c799222440d6cf362062f78be1013661b00c5c6f678b"}, {file = "PyYAML-6.0.1-cp311-cp311-win32.whl", hash = "sha256:1635fd110e8d85d55237ab316b5b011de701ea0f29d07611174a1b42f1444741"}, {file = "PyYAML-6.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34"}, - {file = "PyYAML-6.0.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28"}, - {file = "PyYAML-6.0.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9"}, - {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a08c6f0fe150303c1c6b71ebcd7213c2858041a7e01975da3a99aed1e7a378ef"}, - {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0"}, - {file = "PyYAML-6.0.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4"}, - {file = "PyYAML-6.0.1-cp312-cp312-win32.whl", hash = "sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54"}, - {file = "PyYAML-6.0.1-cp312-cp312-win_amd64.whl", hash = "sha256:0d3304d8c0adc42be59c5f8a4d9e3d7379e6955ad754aa9d6ab7a398b59dd1df"}, {file = "PyYAML-6.0.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:50550eb667afee136e9a77d6dc71ae76a44df8b3e51e41b77f6de2932bfe0f47"}, {file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1fe35611261b29bd1de0070f0b2f47cb6ff71fa6595c077e42bd0c419fa27b98"}, {file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:704219a11b772aea0d8ecd7058d0082713c3562b4e271b849ad7dc4a5c90c13c"}, @@ -2051,7 +2035,6 @@ files = [ {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a0cd17c15d3bb3fa06978b4e8958dcdc6e0174ccea823003a106c7d4d7899ac5"}, {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:28c119d996beec18c05208a8bd78cbe4007878c6dd15091efb73a30e90539696"}, {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7e07cbde391ba96ab58e532ff4803f79c4129397514e1413a7dc761ccd755735"}, - {file = "PyYAML-6.0.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:49a183be227561de579b4a36efbb21b3eab9651dd81b1858589f796549873dd6"}, {file = "PyYAML-6.0.1-cp38-cp38-win32.whl", hash = "sha256:184c5108a2aca3c5b3d3bf9395d50893a7ab82a38004c8f61c258d4428e80206"}, {file = "PyYAML-6.0.1-cp38-cp38-win_amd64.whl", hash = "sha256:1e2722cc9fbb45d9b87631ac70924c11d3a401b2d7f410cc0e3bbf249f2dca62"}, {file = "PyYAML-6.0.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:9eb6caa9a297fc2c2fb8862bc5370d0303ddba53ba97e71f08023b6cd73d16a8"}, @@ -2059,7 +2042,6 @@ files = [ {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5773183b6446b2c99bb77e77595dd486303b4faab2b086e7b17bc6bef28865f6"}, {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:b786eecbdf8499b9ca1d697215862083bd6d2a99965554781d0d8d1ad31e13a0"}, {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bc1bf2925a1ecd43da378f4db9e4f799775d6367bdb94671027b73b393a7c42c"}, - {file = "PyYAML-6.0.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:04ac92ad1925b2cff1db0cfebffb6ffc43457495c9b3c39d3fcae417d7125dc5"}, {file = "PyYAML-6.0.1-cp39-cp39-win32.whl", hash = "sha256:faca3bdcf85b2fc05d06ff3fbc1f83e1391b3e724afa3feba7d13eeab355484c"}, {file = "PyYAML-6.0.1-cp39-cp39-win_amd64.whl", hash = "sha256:510c9deebc5c0225e8c96813043e62b680ba2f9c50a08d3724c7f28a747d1486"}, {file = "PyYAML-6.0.1.tar.gz", hash = "sha256:bfdf460b1736c775f2ba9f6a92bca30bc2095067b8a9d77876d1fad6cc3b4a43"}, @@ -2623,4 +2605,4 @@ test = ["big-O", "importlib-resources", "jaraco.functools", "jaraco.itertools", [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "dec1bd6dcc80dbbb4038850c7c8fc425ef0f65b178e092909e192cd763f9c3d7" +content-hash = "6755bba3f464841de4d30c5e61a122f3aa4b42632da50d03921b37c948493096" diff --git a/pyproject.toml b/pyproject.toml index 741ef453d..54ac763ea 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,7 @@ authors = [] [tool.poetry.dependencies] python = "^3.10" -ops = "^2.6.0,<2.10.0" +ops = "^2.14.0" lightkube = "^0.14.0" tenacity = "^8.2.3" jinja2 = "^3.1.2" @@ -57,7 +57,7 @@ pytest-xdist = "^3.3.1" pytest-forked = "^1.6.0" pytest-cov = "^4.1.0" ops-scenario = "^5.6.2" -ops = "<2.10.0" +ops = "^2.14.0" pytest-mock = "^3.11.1" [tool.poetry.group.integration.dependencies] @@ -69,7 +69,7 @@ juju = "^3.2.2" mysql-connector-python = "~8.0.33" pyyaml = "^6.0.1" tenacity = "^8.2.2" -ops = "<2.10.0" +ops = "^2.14.0" allure-pytest = "^2.13.2" allure-pytest-collection-report = {git = "https://github.com/canonical/data-platform-workflows", tag = "v16.2.0", subdirectory = "python/pytest_plugins/allure_pytest_collection_report"} diff --git a/src/abstract_charm.py b/src/abstract_charm.py index 5c035ee23..c390ce36a 100644 --- a/src/abstract_charm.py +++ b/src/abstract_charm.py @@ -318,7 +318,7 @@ def reconcile(self, event=None) -> None: # noqa: C901 logger.warning( "Modifying relations during an upgrade is not supported. The charm may be in a broken, unrecoverable state. Re-deploy the charm" ) - self._database_provides.delete_all_databags() + self._database_provides.delete_all_databags(event) elif ( not self._upgrade.in_progress and isinstance(workload_, workload.AuthenticatedWorkload) diff --git a/src/relations/database_provides.py b/src/relations/database_provides.py index 08cb70484..370896b6d 100644 --- a/src/relations/database_provides.py +++ b/src/relations/database_provides.py @@ -182,10 +182,24 @@ def __init__(self, charm_: "abstract_charm.MySQLRouterCharm") -> None: charm_.framework.observe(self._interface.on.database_requested, charm_.reconcile) charm_.framework.observe(charm_.on[self._NAME].relation_broken, charm_.reconcile) + # TODO python3.10 min version: Use `list` instead of `typing.List` + def _relations(self, event) -> typing.List[ops.Relation]: + """All relations, including relations that are breaking + + Needed because of breaking change in ops 2.10 + https://github.com/canonical/operator/pull/1091#issuecomment-1888644075 + + May break during deferred ops events or collect status ops events + (https://github.com/canonical/operator/pull/1091#issuecomment-2191460188) + """ + if isinstance(event, ops.RelationBrokenEvent): + return [*self._interface.relations, event.relation] + return self._interface.relations + def external_connectivity(self, event) -> bool: """Whether any of the relations are marked as external.""" requested_users = [] - for relation in self._interface.relations: + for relation in self._relations(event): try: requested_users.append( _RelationThatRequestedUser( @@ -200,11 +214,10 @@ def external_connectivity(self, event) -> bool: pass return any(relation.external_connectivity for relation in requested_users) - @property # TODO python3.10 min version: Use `list` instead of `typing.List` - def _shared_users(self) -> typing.List[_RelationWithSharedUser]: + def _shared_users(self, event) -> typing.List[_RelationWithSharedUser]: shared_users = [] - for relation in self._interface.relations: + for relation in self._relations(event): try: shared_users.append( _RelationWithSharedUser(relation=relation, interface=self._interface) @@ -247,9 +260,9 @@ def reconcile_users( _UnsupportedExtraUserRole, ): pass - logger.debug(f"State of reconcile users {requested_users=}, {self._shared_users=}") + logger.debug(f"State of reconcile users {requested_users=}, {self._shared_users(event)=}") for relation in requested_users: - if relation not in self._shared_users: + if relation not in self._shared_users(event): relation.create_database_and_user( router_read_write_endpoint=router_read_write_endpoint, router_read_only_endpoint=router_read_only_endpoint, @@ -257,7 +270,7 @@ def reconcile_users( exposed_read_only_endpoint=exposed_read_only_endpoint, shell=shell, ) - for relation in self._shared_users: + for relation in self._shared_users(event): if relation not in requested_users: relation.delete_user(shell=shell) logger.debug( @@ -265,7 +278,7 @@ def reconcile_users( f"{exposed_read_write_endpoint=}, {exposed_read_only_endpoint=}" ) - def delete_all_databags(self) -> None: + def delete_all_databags(self, event) -> None: """Remove connection information from all databags. Called when relation with MySQL is breaking @@ -274,7 +287,7 @@ def delete_all_databags(self) -> None: will need to be created. """ logger.debug("Deleting all application databags") - for relation in self._shared_users: + for relation in self._shared_users(event): # MySQL charm will delete user; just delete databag relation.delete_databag() logger.debug("Deleted all application databags") diff --git a/src/relations/database_requires.py b/src/relations/database_requires.py index bdb23da37..7f385a9aa 100644 --- a/src/relations/database_requires.py +++ b/src/relations/database_requires.py @@ -69,7 +69,15 @@ class CompleteConnectionInformation(ConnectionInformation): """ def __init__(self, *, interface: data_interfaces.DatabaseRequires, event) -> None: - relations = interface.relations + # Needed because of breaking change in ops 2.10 + # https://github.com/canonical/operator/pull/1091#issuecomment-1888644075 + # May break during deferred ops events or collect status ops events + # (https://github.com/canonical/operator/pull/1091#issuecomment-2191460188) + if isinstance(event, ops.RelationBrokenEvent): + relations = [*interface.relations, event.relation] + else: + relations = interface.relations + endpoint_name = interface.relation_name if not relations: raise _MissingRelation(endpoint_name=endpoint_name) From 9da1f3ca2ba45a1623b60a4f95270eb459a67038 Mon Sep 17 00:00:00 2001 From: Carl Csaposs Date: Wed, 26 Jun 2024 13:46:26 +0200 Subject: [PATCH 2/4] Update ops-scenario --- poetry.lock | 31 +++---------------- pyproject.toml | 2 +- .../test_database_relations_breaking.py | 4 +-- 3 files changed, 8 insertions(+), 29 deletions(-) diff --git a/poetry.lock b/poetry.lock index 3ee2b448a..4323d0b30 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1360,19 +1360,18 @@ docs = ["canonical-sphinx-extensions", "furo", "linkify-it-py", "myst-parser", " [[package]] name = "ops-scenario" -version = "5.6.2" +version = "6.1.1" description = "Python library providing a state-transition testing API for Operator Framework charms." optional = false python-versions = ">=3.8" files = [ - {file = "ops-scenario-5.6.2.tar.gz", hash = "sha256:0a48e97b406ea9271ea9d683e3ef355f887fa0ab651fd7352e4de214eeaa96c1"}, - {file = "ops_scenario-5.6.2-py3-none-any.whl", hash = "sha256:b75c9e2199b17da355eda4c4eab1f4450067f0f3feb1f4215858e4c90fa6f656"}, + {file = "ops_scenario-6.1.1-py3-none-any.whl", hash = "sha256:358b321c8091b1c1e2ec7df1014c6052416b9bf4d6259ea8f35bc90caa727340"}, + {file = "ops_scenario-6.1.1.tar.gz", hash = "sha256:55d218cd4ea08afcdb2fc9e41a3364a3c1541e3a7c93ab14b2b7fc96e51a91de"}, ] [package.dependencies] -ops = ">=2.6" +ops = ">=2.10" PyYAML = ">=6.0.1" -typer = "0.7.0" [[package]] name = "packaging" @@ -2340,26 +2339,6 @@ files = [ docs = ["myst-parser", "pydata-sphinx-theme", "sphinx"] test = ["argcomplete (>=2.0)", "pre-commit", "pytest", "pytest-mock"] -[[package]] -name = "typer" -version = "0.7.0" -description = "Typer, build great CLIs. Easy to code. Based on Python type hints." -optional = false -python-versions = ">=3.6" -files = [ - {file = "typer-0.7.0-py3-none-any.whl", hash = "sha256:b5e704f4e48ec263de1c0b3a2387cd405a13767d2f907f44c1a08cbad96f606d"}, - {file = "typer-0.7.0.tar.gz", hash = "sha256:ff797846578a9f2a201b53442aedeb543319466870fbe1c701eab66dd7681165"}, -] - -[package.dependencies] -click = ">=7.1.1,<9.0.0" - -[package.extras] -all = ["colorama (>=0.4.3,<0.5.0)", "rich (>=10.11.0,<13.0.0)", "shellingham (>=1.3.0,<2.0.0)"] -dev = ["autoflake (>=1.3.1,<2.0.0)", "flake8 (>=3.8.3,<4.0.0)", "pre-commit (>=2.17.0,<3.0.0)"] -doc = ["cairosvg (>=2.5.2,<3.0.0)", "mdx-include (>=1.4.1,<2.0.0)", "mkdocs (>=1.1.2,<2.0.0)", "mkdocs-material (>=8.1.4,<9.0.0)", "pillow (>=9.3.0,<10.0.0)"] -test = ["black (>=22.3.0,<23.0.0)", "coverage (>=6.2,<7.0)", "isort (>=5.0.6,<6.0.0)", "mypy (==0.910)", "pytest (>=4.4.0,<8.0.0)", "pytest-cov (>=2.10.0,<5.0.0)", "pytest-sugar (>=0.9.4,<0.10.0)", "pytest-xdist (>=1.32.0,<4.0.0)", "rich (>=10.11.0,<13.0.0)", "shellingham (>=1.3.0,<2.0.0)"] - [[package]] name = "typing-extensions" version = "4.7.1" @@ -2605,4 +2584,4 @@ test = ["big-O", "importlib-resources", "jaraco.functools", "jaraco.itertools", [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "6755bba3f464841de4d30c5e61a122f3aa4b42632da50d03921b37c948493096" +content-hash = "5dda777a8ccd3144b63bdf904c5ba423eae34515a58830f55b58a0a983d6d16a" diff --git a/pyproject.toml b/pyproject.toml index 54ac763ea..9a3609eb4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -56,7 +56,7 @@ pytest = "^7.4.0" pytest-xdist = "^3.3.1" pytest-forked = "^1.6.0" pytest-cov = "^4.1.0" -ops-scenario = "^5.6.2" +ops-scenario = "^6.1.1" ops = "^2.14.0" pytest-mock = "^3.11.1" diff --git a/tests/unit/scenario_/database_relations/test_database_relations_breaking.py b/tests/unit/scenario_/database_relations/test_database_relations_breaking.py index bf0fee96a..b34354370 100644 --- a/tests/unit/scenario_/database_relations/test_database_relations_breaking.py +++ b/tests/unit/scenario_/database_relations/test_database_relations_breaking.py @@ -40,7 +40,7 @@ def test_breaking_requires_and_complete_provides( secret = scenario.Secret( id="foo", contents={0: {"username": "foouser", "password": "foobar"}}, - owner="application", + owner="app", ) relation = relation.replace( local_app_data={ @@ -91,7 +91,7 @@ def test_complete_requires_and_breaking_provides( secret = scenario.Secret( id=f"foo-{relation.relation_id}", contents={0: {"username": "foouser", "password": "foobar"}}, - owner="application", + owner="app", ) relation = relation.replace( local_app_data={ From 3b111312ed26ff56b0b7391f121391618f49ab46 Mon Sep 17 00:00:00 2001 From: Carl Csaposs Date: Wed, 26 Jun 2024 16:53:15 +0200 Subject: [PATCH 3/4] Check endpoint name --- src/relations/database_provides.py | 2 +- src/relations/database_requires.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/relations/database_provides.py b/src/relations/database_provides.py index 370896b6d..c570c4bfe 100644 --- a/src/relations/database_provides.py +++ b/src/relations/database_provides.py @@ -192,7 +192,7 @@ def _relations(self, event) -> typing.List[ops.Relation]: May break during deferred ops events or collect status ops events (https://github.com/canonical/operator/pull/1091#issuecomment-2191460188) """ - if isinstance(event, ops.RelationBrokenEvent): + if isinstance(event, ops.RelationBrokenEvent) and event.relation.name == self._NAME: return [*self._interface.relations, event.relation] return self._interface.relations diff --git a/src/relations/database_requires.py b/src/relations/database_requires.py index 7f385a9aa..aa96796c1 100644 --- a/src/relations/database_requires.py +++ b/src/relations/database_requires.py @@ -73,7 +73,10 @@ def __init__(self, *, interface: data_interfaces.DatabaseRequires, event) -> Non # https://github.com/canonical/operator/pull/1091#issuecomment-1888644075 # May break during deferred ops events or collect status ops events # (https://github.com/canonical/operator/pull/1091#issuecomment-2191460188) - if isinstance(event, ops.RelationBrokenEvent): + if ( + isinstance(event, ops.RelationBrokenEvent) + and event.relation.name == interface.relation_name + ): relations = [*interface.relations, event.relation] else: relations = interface.relations From 9b5e8a7c7d775360c8b3257b7d637ead6e90f3da Mon Sep 17 00:00:00 2001 From: Carl Csaposs Date: Tue, 2 Jul 2024 14:25:04 +0200 Subject: [PATCH 4/4] replace addl .interface.relations calls --- src/relations/database_provides.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/relations/database_provides.py b/src/relations/database_provides.py index c570c4bfe..a8a38b6f1 100644 --- a/src/relations/database_provides.py +++ b/src/relations/database_provides.py @@ -247,7 +247,7 @@ def reconcile_users( f"{exposed_read_write_endpoint=}, {exposed_read_only_endpoint=}" ) requested_users = [] - for relation in self._interface.relations: + for relation in self._relations(event): try: requested_users.append( _RelationThatRequestedUser( @@ -301,7 +301,7 @@ def get_status(self, event) -> typing.Optional[ops.StatusBase]: ) # TODO python3.10 min version: Use `list` instead of `typing.List` exceptions: typing.List[status_exception.StatusException] = [] - for relation in self._interface.relations: + for relation in self._relations(event): try: requested_users.append( _RelationThatRequestedUser(