Skip to content

STRDT with an unregistered datatype IRI fails the query instead of producing the literal #1765

Closed

Description

@bplatz

Raised in review of #1746, not introduced by it. Third site on the same literal-identity seam that PR fixes, and the only one that fails hard.

Problem

STRDT(?v, <iri>) where <iri>'s namespace is not registered on the ledger aborts the whole query instead of producing the literal.

$ # ledger holds ex:a ex:q "a"
SELECT ?s ?x WHERE { ?s ex:q ?v BIND(STRDT(?v, <http://no-such-ns.example.com/T>) AS ?x) }
→ Query error: Invalid filter: Unknown datatype IRI: http://no-such-ns.example.com/T

SELECT ?s ?x WHERE { ?s ex:q ?v BIND(STRDT(?v, xsd:token) AS ?x) }
→ ex:a, {"@value": "a", "@type": "xsd:token"}          # registered: fine

Per SPARQL 1.1 §17.4.2.9, STRDT builds a literal from a simple literal and any datatype IRI. The IRI does not have to be known to the store, and nothing about the result depends on it being resolvable — DATATYPE() on the same expression already returns the IRI happily:

SELECT ?s (DATATYPE(STRDT(?v, <http://no-such-ns.example.com/T>)) AS ?d) WHERE { ?s ex:q ?v }
→ ex:a, http://no-such-ns.example.com/T

So the failure is specific to materializing the value into a Binding, which BIND does and DATATYPE() does not.

Mechanism

ComparableValue::to_binding (fluree-db-query/src/eval/value.rs:~636) resolves the datatype with the strict encoder and turns None into an error:

let dt = ctx
    .active_snapshot
    .encode_iri_strict(&dt_iri)
    .ok_or_else(|| QueryError::InvalidFilter(format!("Unknown datatype IRI: {dt_iri}")))?;

encode_iri_strict returns None exactly when the IRI's canonical prefix is not a registered namespace on this ledger — a fact about the data, not about the expression's validity.

QueryError::InvalidFilter is not in demotes_to_unbound_in_extend (fluree-db-query/src/error.rs:221, which covers only Arithmetic and Comparison), so the error is not demoted to unbound under the §18.5 Extend rule either — it propagates and fails the request.

Why this is the odd one out

Every other place that resolves a datatype IRI for term identity uses the non-strict encoder, which yields the EMPTY-namespace full-IRI Sid — a well-formed term that simply matches nothing stored:

Only the expression path is strict, and only it raises.

Suggested fix

Resolve through encode_iri (non-strict) so the constructed literal carries Sid(EMPTY, <full IRI>) — the same form storage produces for an unregistered namespace, and the same form the two lowering sites now use. STRDT then returns a literal that is a valid RDF term, compares equal only to itself, and matches nothing in the store, which is the correct answer for a datatype the ledger has never seen.

Worth checking STRLANG and the xsd:* cast functions for the same pattern while in there, plus whether any caller depends on the current error.

Not in scope

Whether InvalidFilter should join the Extend demotion set is a separate question — with the encoder fixed there is nothing left to demote here.

Activity

  1. added
    bug
    P3
    area:sparql
    on Sep 3, 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:sparqlbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions