Skip to content

@unique doesn't work with quotes #9405

@StefanTheWiz

Description

@StefanTheWiz

Describe the bug

Adding @unique to a schema type results in failure to ingest strings that contain double quotes (even though the quotes are escaped).

Strings containing single quotes seem to work fine.

To Reproduce

Steps to reproduce the behavior:

  1. Run the docker image (docker run --rm -it -p 8080:8080 -p 9080:9080 dgraph/standalone:v24.1.2 or v25.0.0-preview1)
  2. Create the following schema predicate
Example.name: string @unique @index(exact, term) .
  1. Execute the following mutations:
curl -q -H "Content-Type: application/json" -X POST "http://localhost:8080/mutate?commitNow=true" -d '
{
  "set": {
    "Example.name": "The \"problem\" is the quotes (json)"
  }
}' | jq

curl -q -H "Content-Type: application/json" -X POST "http://localhost:8080/mutate?commitNow=true" -d '
{
  "set": {
    "Example.name": "but it is fine without the quotes (json)"
  }
}' | jq

curl -q -H "Content-Type: application/rdf" -X POST "http://localhost:8080/mutate?commitNow=true" -d '
{
  set {
    _:v <Example.name> "The \"problem\" is the quotes (rdf)" .
  }
}' | jq

curl -q -H "Content-Type: application/rdf" -X POST "http://localhost:8080/mutate?commitNow=true" -d '
{
  set {
    _:v <Example.name> "but it is fine without the quotes (rdf)" .
  }
}' | jq
  1. See errors for mutations 1 and 3:
{
  "errors": [
    {
      "message": "line 1 column 63: Expected comma or language but got: problem",
      "extensions": {
        "code": "ErrorInvalidRequest"
      }
    }
  ],
  "data": null
}
  1. Drop all data, including schema and types.
  2. Create the following schema predicate, this time without @unique:
Example.name: string @index(exact, term) .
  1. The data is ingested without any problems
{
  result (func: has(Example.name)) {
    uid
    Example.name
  }
}

returns:

{
  "data": {
    "result": [
      {
        "uid": "0x19",
        "Example.name": "The \"problem\" is the quotes (json)"
      },
      {
        "uid": "0x1a",
        "Example.name": "but it is fine without the quotes (json)"
      },
      {
        "uid": "0x1b",
        "Example.name": "The \"problem\" is the quotes (rdf)"
      },
      {
        "uid": "0x1c",
        "Example.name": "but it is fine without the quotes (rdf)"
      }
    ]
  }
}

Expected behavior

All these test queries should succeed.
For the data I'm trying to represent in Dgraph, quotes in Example.name are an allowed character.

Environment

  • OS: Docker images for both AMD64 and ARM64
  • Version v24.1.2 and v25.0.0-preview1

Activity

StefanTheWiz

StefanTheWiz commented on Jun 9, 2025

@StefanTheWiz
Author

When can we expect the fix to be released?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @mangalaman93@StefanTheWiz

    Issue actions

      `@unique` doesn't work with quotes · Issue #9405 · hypermodeinc/dgraph