Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defer database event when username is None #1005

Merged
merged 5 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions charms/jimm-k8s/src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,14 @@ def _on_dashboard_relation_joined(self, event: RelationJoinedEvent):
def _on_database_event(self, event: DatabaseEvent) -> None:
"""Database event handler."""

if event.username is None or event.password is None:
event.defer()
logger.info(
"(postgresql) Relation data is not complete (missing `username` or `password` field); "
"deferring the event."
)
return

# get the first endpoint from a comma separate list
ep = event.endpoints.split(",", 1)[0]
# compose the db connection string
Expand Down
2 changes: 1 addition & 1 deletion charms/jimm/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
markupsafe>=2.0.1
Jinja2 >= 2.11.3
ops >= 1.4.0
ops >= 2.0.0
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like this is fine

charmhelpers >= 0.20.22
hvac >= 0.11.0
pydantic == 1.10.10
Expand Down
8 changes: 8 additions & 0 deletions charms/jimm/src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@ def _on_database_event(self, event: DatabaseRequiresEvent):
event.defer()
return

if event.username is None or event.password is None:
event.defer()
logger.info(
"(postgresql) Relation data is not complete (missing `username` or `password` field); "
"deferring the event."
)
return

# get the first endpoint from a comma separate list
host = event.endpoints.split(",", 1)[0]
# compose the db connection string
Expand Down