Fail meaningfully on metadata a column cannot hold - #8518
Open
Shubham Padkonde (Shubham-Padkonde) wants to merge 2 commits into
Open
Shubham Padkonde (Shubham-Padkonde) wants to merge 2 commits into
Shubham Padkonde (Shubham-Padkonde) wants to merge 2 commits into
Conversation
Adding metadata whose value is a nested dict or a sequence surfaced as a bare sqlite3 binding error wrapped in the generic rollback RuntimeError: sqlite3.ProgrammingError: Error binding parameter 1: type 'list' is not supported which names neither the tag nor what to do about it. validate_dynamic_column_data already rejects invalid tags and None with a clear message, so extend it to reject values SQLite cannot store. The check asks SQLite itself whether the value binds rather than comparing against a list of types, so values NumPy registers an adapter for -- scalars and arrays -- keep working as before. Fixes microsoft#1444 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Shubham Padkonde (Shubham-Padkonde)
requested a review
from a team
as a code owner
September 21, 2026 04:56
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in 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.
Description
Adding metadata whose value is a nested dict or a sequence has failed with a raw sqlite3 binding error since #1444 was filed. On
mainatf6b9dd6:which names neither the offending tag nor what to do instead. Measured across value types:
{"b": 1}sqlite3.ProgrammingError: ... type 'dict' is not supported[1, 2]... type 'list' is not supported(1, 2)... type 'tuple' is not supported{1, 2}... type 'set' is not supportedIn the issue thread the ask was specifically to "fail in a meaningful way if you try to add nested fields as metadata", with the json-serialization workaround being the recommendation for the underlying use case. That is what this does — it does not try to pack/unpack sequences automatically.
validate_dynamic_column_dataalready rejects invalid tags andNonevalues with clear messages, so this extends it with the same shape of check. After:The error keeps the established house style: validation raises inside the transaction and the message reaches the caller through
__cause__, which is how the existing tag andNonechecks behave and whaterror_caused_byin the test suite reads.Why not a list of accepted types
QCoDeS registers sqlite3 adapters for NumPy types, so an allow-list would reject values that store correctly today. I checked what actually round-trips before the change:
np.int64(3)intnp.float64(2.5)floatnp.bool_(True)bytesnp.str_("s")strnp.array([1, 2])bytesSo the check asks SQLite itself whether the value binds, with a bare
SELECT ?against a throwaway in-memory connection. Anything with a registered adapter — including all of the above — is still accepted, and nothing is written anywhere by the probe. All five still store after the change.Related Issue(s)
Fixes #1444
Testing
Extended
test_metadataintests/dataset/test_dataset_basic.py, next to the existing bad-tag andNoneassertions, coveringdict,list,tupleandset, plus an assertion thatnp.int64metadata still round-trips.Without the change the new assertion fails:
With it:
ruff checkandruff format --checkare clean on both touched files.I could not run
mypyon the change: it exits with anINTERNAL ERRORinsidesrc/qcodes/dataset/data_set_protocol.pyon this machine (mypy 2.3.1). That reproduces on cleanmainwith my changes stashed, so it is not caused by this PR, but it does mean the type checking here has only been validated by CI rather than locally.Backwards-compatibility
A value that previously raised
sqlite3.ProgrammingErrornow raisesTypeError, both wrapped in the same rollbackRuntimeError. Nothing that stored successfully before is rejected now — that is what the NumPy table above is there to show.Code catching the inner
sqlite3.ProgrammingErrorspecifically would need to catchTypeErrorinstead, though that seems an unlikely thing to have depended on given the error was the bug being reported.Documentation
The docstring of
validate_dynamic_column_datanow lists what it raises and why. The surrounding docstrings already said "None is not a valid value"; the new sentence extends that to nested values.Disclosure: this change was written by Claude Code (Claude Opus 5) working as my agent, at my direction. The error messages and test output quoted above come from real runs in my local environment; I am accountable for the content of this PR and happy to iterate on review feedback.
🤖 Generated with Claude Code