Skip to content

docs(python): how query results show unbound variables and dates - #2155

Merged
bplatz merged 3 commits into
mainfrom
docs/python-value-mode
Oct 23, 2026
Merged

bplatz merged 3 commits into
mainfrom
docs/python-value-mode

Conversation

@bplatz

@bplatz bplatz commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

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 OPTIONAL that matched nothing) is None, and its column is still in the Record. So r.get("desc", "") returns None: get's default applies only when the result has no such column. The README now says so, and Record.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):

  • an xsd:dateTime is a datetime in UTC, whatever offset it was written with, so isoformat() writes +00:00 where the data said Z;
  • an xsd:date or xsd:time has no offset;
  • fractions of a second stop at the microsecond.

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.py also said the engine writes up to nine fractional digits. It writes at most six.

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.
@bplatz bplatz added the documentation Improvements or additions to documentation label Oct 21, 2026
@bplatz
bplatz requested a review from a team October 21, 2026 21:33

@aaj3f aaj3f left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@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 python job 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.

Comment thread fluree-db-python/README.md Outdated
`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)):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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:

Suggested change
([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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 3947833


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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 3947833

…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.
@bplatz
bplatz merged commit 1ad0b18 into main Oct 23, 2026
19 checks passed
@bplatz
bplatz deleted the docs/python-value-mode branch October 23, 2026 22:03
bplatz added a commit that referenced this pull request Oct 24, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants