[BUG] Empty string id is not correctly validated by forceId

Offen
#1,519 9 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
35/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
javascript, mongodb, node.js
Bereich
backend, database

Rechercherichtung

Reproduziere das Problem mit dem verknüpften loopback-sandbox-Branch und einem Modell, das mit forceId: true konfiguriert ist, sowie einer MongoDB-Datenquelle. Verfolge den API-Erstellungspfad und die forceId-Validierung für eine explizit leere id; abgeschlossen ist die Aufgabe, wenn die Anfrage mit dem dokumentierten 422 ValidationError abgelehnt wird, anstatt einen Datenbankeintrag zu erstellen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

bug good first issue help wanted

Description/Steps to reproduce

  • define a model with forceId: true
  • associate this model to a mongodb data source
  • call the API to create a new model with an explicit empty string id
curl -X POST --header "Content-Type: application/json" --header "Accept: application/json" -d "{
  \"id\": \"\"
}" "http://localhost:3000/api/foos"
  • this call creates a db entry with empty id and returns: {"id": ""}

Seems related to #1453 (see my comment)

Link to reproduction sandbox

https://github.com/simonbrunel/loopback-sandbox/tree/bug/empty-id-mongodb

Expected result

{
  "error": {
    "name": "ValidationError",
    "status": 422,
    "message": "The `foo` instance is not valid. Details : `id` can't be set (value: \"\").",
    "statusCode": 422,
    "details": {
      "context": "foo",
      "codes": {
        "id": [
          "absence"
        ]
      },
      "messages": {
        "id": [
          "can't be set"
        ]
      }
    }
  }
}

Additional information

node v6.11.3, Windows 10 64bit

npm ls --prod --depth 0 | grep loopback
[email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
Vorherrschende Sprache
JavaScript
Sterne
279
Forks
362
Ø Merge
21 Std. 14 Min.
Gemergte PRs (30 T.)
16

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus loopbackio/loopback-datasource-juggler

Alle Issues in loopbackio/loopback-datasource-juggler

Ähnliche Issues

Weitere Issues zu JavaScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.