-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Make Harness more strict in validating relation data contents (on write) #786
Merged
rwcarlsen
merged 3 commits into
canonical:main
from
PietroPasotti:harness-relation-data-strict
Jun 29, 2022
Merged
Make Harness more strict in validating relation data contents (on write) #786
rwcarlsen
merged 3 commits into
canonical:main
from
PietroPasotti:harness-relation-data-strict
Jun 29, 2022
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PietroPasotti
changed the title
Fixed bug with relation data keys allowed to be non-string
Make Harness more strict in validating relation data contents (on write)
Jun 24, 2022
rwcarlsen
approved these changes
Jun 24, 2022
pengale
approved these changes
Jun 29, 2022
rwcarlsen
force-pushed
the
harness-relation-data-strict
branch
from
June 29, 2022 20:51
32ef8bf
to
5e5660a
Compare
This was referenced Oct 20, 2022
benhoyt
added a commit
to benhoyt/traefik-k8s-operator
that referenced
this pull request
Jan 18, 2023
* test_show_proxied_endpoints_action_no_relations previously had error "'ConfigData' object does not support item assignment". This was caused by canonical/operator#787 and the fix is to stop setting items on Model.config._data directly. Do it with update_config, but suppress the config-changed event it triggers. * test_ingress_app_provider_relate_provide previosly had error ops.model.RelationDataTypeError: relation data values must be strings, not <class 'bool'> caused by canonical/operator#786 and the fix is to send string values instead of Python bools (lowercase as these would be sent to relation-set as YAML). * Fix unit name in test_lib_per_unit* tests (it should be the remote app) to silence the warnings about that. Also remove the unexpected config value "asyncio_mode" in pyproject.toml's pytest settings to suppress the warning about that. In addition, tweak some type annotations in the ingress charm libs to fix these Pyright errors (I haven't done "charmcraft publish-lib" or similar though): pyright 1.1.290 /home/ben/w/traefik-k8s-operator/lib/charms/traefik_k8s/v1/ingress.py /home/ben/w/traefik-k8s-operator/lib/charms/traefik_k8s/v1/ingress.py:218:16 - error: Expression of type "_RelationEventSnapshot" cannot be assigned to return type "dict[Unknown, Unknown]" "_RelationEventSnapshot" is incompatible with "dict[Unknown, Unknown]" (reportGeneralTypeIssues) /home/ben/w/traefik-k8s-operator/lib/charms/traefik_k8s/v1/ingress.py:221:25 - error: Argument of type "dict[Unknown, Unknown]" cannot be assigned to parameter "snapshot" of type "_RelationEventSnapshot" in function "restore" "dict[Unknown, Unknown]" is incompatible with "_RelationEventSnapshot" (reportGeneralTypeIssues) /home/ben/w/traefik-k8s-operator/lib/charms/traefik_k8s/v1/ingress.py:253:10 - error: Expression of type "IngressPerAppProviderEvents" cannot be assigned to declared type "property" "IngressPerAppProviderEvents" is incompatible with "property" (reportGeneralTypeIssues) /home/ben/w/traefik-k8s-operator/lib/charms/traefik_k8s/v1/ingress.py:409:10 - error: Expression of type "IngressPerAppRequirerEvents" cannot be assigned to declared type "property" "IngressPerAppRequirerEvents" is incompatible with "property" (reportGeneralTypeIssues) /home/ben/w/traefik-k8s-operator/lib/charms/traefik_k8s/v1/ingress_per_unit.py /home/ben/w/traefik-k8s-operator/lib/charms/traefik_k8s/v1/ingress_per_unit.py:320:10 - error: Expression of type "IngressPerUnitProviderEvents" cannot be assigned to declared type "property" "IngressPerUnitProviderEvents" is incompatible with "property" (reportGeneralTypeIssues) /home/ben/w/traefik-k8s-operator/lib/charms/traefik_k8s/v1/ingress_per_unit.py:578:16 - error: Expression of type "_RelationEventSnapshot" cannot be assigned to return type "dict[Unknown, Unknown]" "_RelationEventSnapshot" is incompatible with "dict[Unknown, Unknown]" (reportGeneralTypeIssues) /home/ben/w/traefik-k8s-operator/lib/charms/traefik_k8s/v1/ingress_per_unit.py:581:25 - error: Argument of type "dict[Unknown, Unknown]" cannot be assigned to parameter "snapshot" of type "_RelationEventSnapshot" in function "restore" "dict[Unknown, Unknown]" is incompatible with "_RelationEventSnapshot" (reportGeneralTypeIssues) 7 errors, 0 warnings, 0 informations
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Brings the harness in line with the behaviour of RelationDataContents: key/value pairs MUST be of type str:str. Else: ModelError.
The harness is with this PR more 'correct' than ops itself, because while I was writing out this code I found #785. So ops allows you to write Any:str to relation data. Ops forces you to do str:str.
Once #785 is merged, ops will also enforce str:str and the harness will be at the same level.
Checklist
QA steps
Added integration tests for this bug.
Documentation changes
I believe the docs already make it clear that config keys must be strings.
Changelog