Scenario bundle acronym uniqueness is not enforced, and the rejection answers HTTP 200

Abierto
#2,511 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 3 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
55/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
django, python

Línea de trabajo

Start with the browser create and update paths in factsheet/views.py, then read factsheet/helper.py and factsheet/oekg/connection.py to understand the current comparison and graph access. Compare them with oekg/acronyms.py and the server-minted UID work in #2477. Done means browser-created bundles follow the REST API's uniqueness, conflict response, and UID behavior without duplicate or merged records.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug oekg
1. The comparison compares two different things

factsheet/views.py:167-171:

for s, p, o in oekg.triples((None, RDF.type, OEO.OEO_00020227)):
    study_acronym = oekg.value(s, DC.acronym)
    if str(clean_name(acronym)) == str(study_acronym):
        Duplicate_study_factsheet = True

The left side is normalised, the right side is the raw stored value. clean_name
(factsheet/helper.py) replaces spaces, hyphens, %, Ö/ö, /, :, ( and ) with
underscores or expansions — but bundles are stored with dc:acronym set to the unmodified input.

So for an existing bundle with acronym NEP 2037, a second create with the same acronym compares
"NEP_2037" == "NEP 2037" → False, and the duplicate is created. The check only ever fires for
acronyms containing none of the replaced characters.

Effect: acronym uniqueness is silently unenforced for a large share of real acronyms.

The update path has its own copy of the same comparison (:625-634).

2. When it does fire, it answers 200
response = JsonResponse("Factsheet exists", safe=False, content_type="application/json")

No status code, so Django sends 200 OK. A rejected create is indistinguishable from a successful
one for any client that checks status codes rather than parsing the body string. It should be a
409 Conflict.

3. It is an O(bundles) graph scan per create

The check iterates every OEO_00020227 in the graph and issues an oekg.value() per bundle. With
SPARQLUpdateStore as transport (factsheet/oekg/connection.py) each of those is its own HTTP round
trip to Fuseki. A single ASK would answer the same question in one request.

4. Adjacent: the client-supplied uid is unvalidated
uid = request_body["uid"]
study_URI = URIRef("https://openenergyplatform.org/ontology/oekg/" + uid)

A client-supplied string is concatenated straight into the IRI namespace — no UUID check, no
character check. Note the create checks the acronym for duplicates but never the uid, so a
POST carrying an existing uid with a different acronym writes its triples into the existing
bundle's URI: a silent merge.

Suggested fix
  • Compare like with like — normalise both sides, or store the normalised form alongside and compare
    that. Decide which is canonical and write it down.
  • Answer 409 on a duplicate.
  • Replace the scan with a single ASK.
  • Mint the uuid server-side rather than validating a client-supplied one — that closes the
    surface instead of policing it.

This is already built and merged for the REST API: oekg/acronyms.py (#2471) holds the whole
acronym promise, and the server mints the uid (#2477). The fix here is to route the browser's create
through the same code rather than to write a second answer.

Why it matters beyond the browser

The API depends on acronym uniqueness being real: a stateless modelling pipeline re-identifies its
bundle with GET /api/v0/scenario-bundles/?acronym=…, so an unenforced acronym makes re-import pick
the wrong bundle or create duplicates. Academy notebook #2464 teaches exactly that pattern.


Found while charting the OEKG REST API (WF-10, "Idempotent re-import for the modelling pipeline").
Verified still present on develop (f21a6a3b7) on 2026-09-21; line numbers are from that commit.

Lenguaje dominante
Python
Estrellas
65
Forks
28
Merge medio
4 d 7 h
PR fusionados (30 d)
25

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de OpenEnergyPlatform/oeplatform

Todos los issues de OpenEnergyPlatform/oeplatform

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.