Skip to content

STR() returns unbound for gYear-family and duration literals #1994

Open

Description

@bplatz

Summary

STR() returns unbound for literals of these eight datatypes:

  • xsd:gYear, xsd:gYearMonth, xsd:gMonth, xsd:gDay, xsd:gMonthDay
  • xsd:duration, xsd:dayTimeDuration, xsd:yearMonthDuration

The values themselves are stored and returned correctly, and DATATYPE() works. Only the lexical-form conversion fails. SPARQL STR() must return the lexical form of any literal. docs/reference/compatibility.md says so for Fluree specifically: "STR() and every result format return the canonical form", in the paragraph that covers the gYear family. Other temporal types (xsd:date, xsd:dateTime, xsd:time) work.

This is the same on novelty and on indexed data, and on both surfaces (SPARQL STR(?o) and JSON-LD ["bind", "?s", "(str ?o)"]). Reproduced on v4.2.2 (ba984c7f5, current main).

Reproduction

fluree init && fluree create s
fluree insert s '@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . @prefix ex: <http://example.org/> .
ex:a ex:v "2026"^^xsd:gYear , "2026-01"^^xsd:gYearMonth , "--01"^^xsd:gMonth , "---15"^^xsd:gDay ,
         "--01-15"^^xsd:gMonthDay , "P1D"^^xsd:duration , "PT1H"^^xsd:dayTimeDuration ,
         "P1M"^^xsd:yearMonthDuration , "2026-01-15"^^xsd:date .'
fluree query s 'SELECT ?o (DATATYPE(?o) AS ?dt) (COALESCE(STR(?o), "<<unbound>>") AS ?str)
                WHERE { <http://example.org/a> <http://example.org/v> ?o }' --format table
# ?str is "2026-01-15" for the xsd:date row and <<unbound>> for the other eight

Where it goes wrong

TryFrom<&FlakeValue> for ComparableValue (fluree-db-query/src/eval/value.rs:949) maps all eight types to ComparableValue::TypedLiteral { val, .. }. into_string_value (value.rs:652) handles TypedLiteral only when the inner value is String, Long, Double or Boolean, and falls through to _ => None (value.rs:702). eval_str (eval/string.rs:93) therefore gets no string.

Possible fix

Render the inner FlakeValue in its canonical lexical form in that arm, as the serializers already do (the values print correctly in result sets). This touches the shared eval, so a test should cover both the SPARQL and the JSON-LD surface.

Activity

  1. added
    bug
    P3
    area:query
    on Sep 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3area:querybug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions