Skip to content

@unique doesn't work with quotes #9405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
StefanTheWiz opened this issue May 12, 2025 · 1 comment · May be fixed by #9412
Open

@unique doesn't work with quotes #9405

StefanTheWiz opened this issue May 12, 2025 · 1 comment · May be fixed by #9412
Assignees
Labels

Comments

@StefanTheWiz
Copy link

StefanTheWiz commented May 12, 2025

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
Copy link

linear bot commented May 12, 2025

@mangalaman93 mangalaman93 linked a pull request May 16, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging a pull request may close this issue.

2 participants