`Resolver.lookup` always resolves a `$dynamicAnchor` dynamically, so a `$ref` to one behaves like a `$dynamicRef`
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 52/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- python
- Área
- backend-api-design
Línea de trabajo
Start with Resolver.lookup and lookup_recursive_ref, then trace how jsonschema calls lookup for $ref and $dynamicRef. Use the supplied Draft 2020-12 reproduction to check the behavior. Done means $ref returns the static inner schema while $dynamicRef retains dynamic resolution.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Resolver.lookup resolves a fragment that names a $dynamicAnchor through the dynamic scope, and a caller cannot ask for the static target instead. In Draft 2020-12 only $dynamicRef resolves that way; a $ref to the same anchor is static. jsonschema calls lookup for both keywords, so it applies the wrong schema for such a $ref whenever an outer resource has a dynamic anchor of the same name.
Seen with referencing 0.37.0 and with main at 84089b9.
Reproduction
from referencing import Registry
from referencing.jsonschema import DRAFT202012
schema = {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com/root",
"$ref": "inner#item",
"$defs": {
"outer": {"$dynamicAnchor": "item", "type": "null"},
"inner": {"$id": "inner", "$dynamicAnchor": "item", "type": "string"},
},
}
registry = DRAFT202012.create_resource(schema) @ Registry()
resolver = registry.resolver(base_uri="https://example.com/root")
print(resolver.lookup("inner#item").contents)
| Result | |
|---|---|
Expected for a $ref |
{'$id': 'inner', '$dynamicAnchor': 'item', 'type': 'string'} |
| Actual | ❌ Incorrect: {'$dynamicAnchor': 'item', 'type': 'null'} |
https://example.com/inner#item is the inner schema, but lookup returns outer, the root resource's dynamic anchor of that name. That is right for a $dynamicRef and wrong for a $ref. From a resolver with an empty dynamic scope, registry.resolver().lookup("https://example.com/inner#item"), the same reference does return inner.
The visible effect is in jsonschema 4.26.0: Draft202012Validator(schema) rejects "a" and accepts null, the reverse of what the schema says.
Why a $ref should be static
Core §8.2.3.1 on $ref:
This resolution is safe to perform on schema load, as the process of evaluating an instance cannot change how the reference resolves.
§8.2.3.2 on $dynamicRef:
Both the extension point and the runtime-determined extension target are defined with "$dynamicAnchor", and only exhibit runtime dynamic behavior when referenced with "$dynamicRef".
What a fix needs
A way to look up a dynamic anchor statically here, and jsonschema using it for $ref. $recursiveRef is already split like that, with lookup_recursive_ref for the dynamic case.
Other implementations
| Implementation | $ref in the schema above |
|---|---|
Python jsonschema 4.26.0 with referencing 0.37.0 |
❌ Incorrect: "a" invalid, null valid |
@hyperjump/json-schema 1.18.1 (JavaScript) |
✅ Correct: "a" valid, null invalid |
boon 0.6.1 (Rust) |
✅ Correct: "a" valid, null invalid |
ajv 8.20.0 (JavaScript) |
✅ Correct: "a" valid, null invalid |
Rust jsonschema crate 0.61.2 |
❌ Incorrect: "a" invalid, null valid |
The Rust crate has the same behaviour, reported as Stranger6667/jsonschema#1923.
The JSON Schema Test Suite does not catch this: its one case with a $ref to a $dynamicAnchor has a single anchor of that name, so both readings pass it. I have proposed a case that tells them apart in json-schema-org/JSON-Schema-Test-Suite#1279.
- Lenguaje dominante
- Python
- Estrellas
- 56
- Forks
- 55
- Merge medio
- 5 d 22 h
- PR fusionados (30 d)
- 4
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de python-jsonschema/referencing
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
python-jsonschema/referencing#444 · 1 comentario ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
python-jsonschema/referencing#434 ·
-
$ref resolution in a $dynamicRef target ($dynamicAnchor) happening from base URI instead of targetAbierto
Dificultad 4/5 3-5 días Aptitud para principiantes 30/100
python-jsonschema/referencing#445 · 1 comentario ·
-
$dynamicRef doesn't find $dynamicAnchor overrides in root schemas without $idPosiblemente ocupada @aqeelat la tomó hace 174 días. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
python-jsonschema/referencing#366 ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
python-jsonschema/referencing#257 ·
Todos los issues de python-jsonschema/referencing
Issues similares
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 78/100
web-push-libs/pywebpush#216 · 1 comentario ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
AgriciDaniel/claude-seo#572 ·
Los mantenedores suelen responder en 5 días
-
area:print-dispatch
Dificultad 2/5 1-3 horas Aptitud para principiantes 92/100
Los mantenedores suelen responder en 1 día
-
area: docs domain: technical-writing good first issue type: documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
Deepak3699/Ai_Mentor#919 ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día