Repository navigation
docs(python): how query results show unbound variables and dates - #2155
Conversation
An unbound variable reads as None with its column present, so a Record's get() returns None for it, not the default. A dateTime comes back as a UTC datetime and a date or time with no offset, at microsecond precision, as the engine stores them; the README links the engine's account of why.
aaj3f
left a comment
There was a problem hiding this comment.
@bplatz thanks for writing both of these down. They're exactly the kind of thing that bites someone at the REPL, and I like that the README points at the engine's own account of temporal values rather than restating it (so the two can't drift). No design notes from me; two small nits below.
Claude-assisted review below:
✅ Approve with nits.
Docs-only and accurate. I checked each claim against the code rather than the prose: Record.get returns self[key] whenever the column exists (_results.py:53) and to_python keeps an unbound cell as None (_terms.py:191-194), so r.get("desc", "") really is None for an unmatched OPTIONAL; and the temporal bullet matches docs/reference/compatibility.md:125-129 word for word in substance (dateTime applied to UTC, date/time offsets validated then discarded, six fractional digits with trailing zeros dropped). The corrected _iso comment is right too: the slice-and-pad still truncates to six, which is now just defensive.
Two optional nits inline: a deep link for the README's "temporal values" link, and a sibling comment in _terms.py that went stale the same way the "nine digits" one did. Both are minor and non-blocking, but if you agree they're right I'd rather see them folded in here than lost in the backlog.
Adherence to repo commitments:
- Patterns/abstractions: ✔ documents existing behavior, links the canonical engine doc instead of duplicating it.
- Performance (speed first, memory second): ✔ n/a — docs and a docstring.
- Deployment targets: ✔ n/a — Python package docs; the
pythonjob ran on macOS, Ubuntu and Windows. - Testing: ✔ no behavior change; nothing to test.
- Conventions: ✔
docs(python):conventional commit with a body; no attribution trailers.
Verified locally at branch HEAD (ea4ebd930): traced Record.get and to_python for the unbound case, read the temporal paragraphs in compatibility.md and confirmed they're live on the published page under #sparql-11-query; CI green including python on all three OSes.
Approving so you can merge when ready, but maybe worth folding in the two nits first.
| `fluree.LangString`, both `str` subclasses. A literal with no lossless | ||
| Python type stays a `fluree.Literal`. | ||
| - Dates and times come back as Fluree stores them | ||
| ([temporal values](https://fluree.github.io/db/reference/compatibility.html)): |
There was a problem hiding this comment.
🟡 Optional / nit: the link lands at the top of a long "Standards and Feature Flags" page, and the temporal paragraphs are a good way down inside the SPARQL 1.1 Query section.
The published page has a stable sparql-11-query anchor (I checked the rendered HTML), so a deep link gets a reader much closer:
| ([temporal values](https://fluree.github.io/db/reference/compatibility.html)): | |
| ([temporal values](https://fluree.github.io/db/reference/compatibility.html#sparql-11-query)): |
Minor and non-blocking, but if you agree it's right I'd rather see it in this PR than lost in the backlog.
|
|
||
| Before 3.11 it takes no "Z" suffix and only a 3- or 6-digit fraction; the | ||
| engine writes up to 9 digits, cut here to microseconds as 3.11 does.""" | ||
| engine writes at most six digits, without trailing zeros, so the fraction |
There was a problem hiding this comment.
🟡 Optional / nit: this fixes one stale comment in _terms.py, but its neighbor at _terms.py:181-182 went stale the same way: "A date with a timezone has no lossless datetime.date form, so date.fromisoformat rejecting one sends it to the Literal fallback."
Per compatibility.md:125, a date's offset is validated and then discarded at parse, on every path (writes and query constants alike), so an xsd:date result never carries one and that fallback is no longer reachable from engine output. The code is fine to keep as a defensive path; it's just the comment that describes a case that can't arrive anymore. Something like "the engine returns a date with no offset (it discards one at parse), so fromisoformat always takes it" would match the README bullet this PR adds.
Minor and non-blocking, but if you agree I'd rather see it folded in now. Commenting here because line 181 is not in this diff.
…omment The README's temporal-values link now points at the SPARQL 1.1 Query section that explains them, not the top of the page. A comment in _terms.py described a date with an offset reaching the Literal fallback; the engine discards a date's offset at parse, so none does.
Brings #2142, #2144, #2154, #2155, #2156, #2158, #2159, #2165, #2166 and #2167 into next. Where main's RDF lists (#2159) meet next's RDF 1.2 links: - The list view walks an EdgeAnnotation's body; next has no AnnotationTarget. - Export marks annotated edges skipping list rows, and writes an rdf:reifies row as next's @reifies block through main's JsonLdNode, untranslated rows included. - The JSON-LD and import readers keep next's graph argument and triple-term spool records beside main's gap-free list positions and list chunking. - One collection writer: main's shared module, which both JSON-LD and Turtle use, replaces next's Turtle-only one, and now also keeps the labels of blank nodes inside triple terms, of reifiers, and of blank graph names. A reified cell keeps its triples while the well-formed tail after it folds, as JSON-LD's list conversion does; next's writer test now says so. - Hiding list members also turns off next's wildcard lane, which reads leaflets directly, and next's independent-scan count builds its right scan with the same hiding. Elsewhere: - List-predicate discovery opens a leaf ranged unless the store cannot read ranges, which next fetches whole. - GC reports main's walk stop reason without next's removed artifact cache directory. - Tests from main await next's async genesis_ledger, reload with without_storage_lock, and build stores without a cache directory.
Documents two behaviors of query results in the Python package that users have tripped over. No behavior changes.
Unbound variables. A variable left unbound (an
OPTIONALthat matched nothing) isNone, and its column is still in theRecord. Sor.get("desc", "")returnsNone:get's default applies only when the result has no such column. The README now says so, andRecord.get's docstring no longer reads as if an unbound value returns the default.Dates and times. Results carry what the engine stores, which differs from the lexical form written (temporal values):
xsd:dateTimeis adatetimein UTC, whatever offset it was written with, soisoformat()writes+00:00where the data saidZ;xsd:dateorxsd:timehas no offset;The README's "a literal with no lossless Python type stays a
fluree.Literal" read as if these were kept exact, so the new bullet states them and links the engine's explanation.An internal comment in
_terms.pyalso said the engine writes up to nine fractional digits. It writes at most six.