Skip to content

Harden database accessors#1150

Open
mxsrc wants to merge 2 commits into
mainfrom
harden-database
Open

Harden database accessors#1150
mxsrc wants to merge 2 commits into
mainfrom
harden-database

Conversation

@mxsrc

@mxsrc mxsrc commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Internals in the database make it easy to get multiple or no values when they are expected. The same functions are used to return multiple or a single values, differentiated by passing an optional value. If a value is passed that is semantically expected to be present, but None for whatever reason, this causes fault that depend on the individual helper. get_cluster_by_id returns a random cluster in that case, for example.

This PR attempts to alleviate this without touching the database internals:

  • type annotations are added to indicate values passed to the database accessors are non-optional. This can expose the faults before runtime in some situations
  • the accessors are reworked to use a helper that explicitly raises when multiple return values are encountered, but only one is expected

mxsrc added 2 commits June 29, 2026 15:54
Lacking these hid an error where `None` could be passed into
`get_cluster_by_id`, silently yielding a random cluster.
The internals of the database make it easy to inadvertently return
multiple values instead of single ones. This introduces a helper to
catch this situation early and expose it via an exception.
@mxsrc mxsrc force-pushed the harden-database branch from c6f4d28 to d5e84d1 Compare June 29, 2026 13:54
@mxsrc mxsrc requested a review from Hamdy-khader June 29, 2026 16:58
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.

1 participant