neo4j-contrib/neo4j-apoc-procedures

apoc.import.json constraint check error while importing json generated by apoc.export.json.all

Closed this issue · 2 comments

Expected Behavior (Mandatory)

The json files exported using apoc.export.json.all should get imported using apoc.import.json

Actual Behavior (Mandatory)

The error related to constraint check is getting generated even though it should have been fixed as per the fix for the issue 2930

How to Reproduce the Problem

Environment:: docker
Image: neo4j- 5.23.0-community-bullseye image

Docker compose file:

services:
  graph_db:
    image: neo4j:5.23.0-community-bullseye
    ports:
      - "7474:7474"
      - "7687:7687"
    environment:
      NEO4J_AUTH: neo4j/your_passwd
      NEO4J_PLUGINS: '["bloom", "apoc"]'
      NEO4J_apoc_export_file_enabled: "true"
      NEO4J_apoc_import_file_enabled: "true"
      NEO4J_apoc_import_file_use__neo4j__config: "true"

    volumes:
      - ./data:/data
      - ./plugins:/plugins
      - ./import:/var/lib/neo4j/import

Steps

  1. Start the container using docker compose file
  2. Add the graph nodes and relations (no constraints included)
  3. In the browser, generate the json file using CALL apoc.export.json.all("jsonfile.json")
  4. Stop the container
  5. Remove the data in the volume (note: sudo might be required due to folder ownership)
  6. Start the container again
  7. Check (exec into the running container using command docker exec -it <container id> /bin/bash and then check the import folder) that the json file exported earlier is available in the import folder
  8. Try to import the json using CALL apoc.import.json("jsonfile.json")

Currently used versions

Versions

  • OS: Ubuntu 20.04
  • Neo4j: 5.23.0
  • Neo4j-Apoc: 5.23.0

@saurabhkumar Thanks for reporting. We will investigate further and come back to you.

Best regards Louise, Neo4j

Hi!

This isn't a bug, Unique constraints are required to be able to do importing as the error is saying. The linked bug was that this error would happen, and any constraint that was made (e.g an existence constraint) would be accepted, which was incorrect as the constraint must be a uniqueness one.

Unfortunately, the procedure has WRITE mode and not SCHEMA mode, so it is not possible for this behaviour to change. I do see that this is not properly documented, and will amend that :)

Just to be clear, a unique constraint is needed for every imported node/relationship label/type on the importing id. The error message will let you know when a constraint has been missed.