docs: say how to decode a one-off row, and why we do not do it for you #96
No reviewers
Labels
No labels
area:defold
area:docs
area:infra
area:protocol
area:testing
kind:bug
kind:chore
phase:breadth
phase:core
phase:hardening
phase:slice
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
yuris/spacetimedb-defold!96
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "docs-oneoff-decode"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
No behaviour change. Docstring + two pinned test cases.
I set out to make v2 auto-decode one-off query rows, on the reasoning that
tables[i].table_namenames a def so the row could be decoded for the caller, the way cached rows already are. That would have been a bug, and the measurement is the reason it is not in this PR.A def is POSITIONAL, and a one-off projects an arbitrary relation. Decoding a projection against the table's def reads the wrong columns, and it does not have to fail:
messagedefSELECT sender, text FROM messageSELECT id, text, sender FROM messagesenderandtextreversedThe second is three columns of the same widths with two swapped, so the bytes are a valid
messagerow and nothing can catch it. That is the silent-wrong-value classcache.lua:169andprotocol.lua:207already exist to prevent, and it would have arrived through a convenience nobody would think to distrust.So the existing behaviour is correct and stays. What was actually missing is that nothing said so: the docstring gave no recipe for decoding a row and no warning against the obvious wrong one. Both are now there, and both cases are pinned in
test_protocol_v2.lua— the silent one by asserting the swap it produces, so inverting that assertion (what someone would "fix" it to if they believed the shortcut were safe) fails with the swap named.Also corrects a framing error of mine: rows arriving encoded is symmetric, not a v2 wart. v1 hands back encoded JSON strings for the same reason.