neo4j-contrib / neo4j-apoc-procedures

Awesome Procedures On Cypher for Neo4j - codenamed "apoc"                     If you like it, please ★ above ⇧            
https://neo4j.com/labs/apoc
Apache License 2.0
1.72k stars 493 forks source link

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

Closed saurabhkumar closed 1 month ago

saurabhkumar commented 2 months ago

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

Lojjs commented 1 month ago

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

Best regards Louise, Neo4j

gem-neo4j commented 1 month ago

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.