Skip to content

LDPSerializer: attaching non-existent local resource creates it

In a new test (DjangoLDPv2.1)

post = {"@id": "{}/job-offers/{}/".format(settings.BASE_URL, job.slug),
    "skills": {
        "ldp:contains": [
            {"@id": "{}/skills/404/".format(settings.BASE_URL)},
        ]}
}

serializer_class = self._get_serializer_class(JobOffer, 2, ("@id", "title", "skills"))
serializer = serializer_class(data=post, instance=job)
serializer.is_valid(raise_exception=True)
result = serializer.save()

It's established in the existing tests that it is sometimes the desired behaviour to create a resource which there is no pre-existing reference to:

  • external resources
  • new resources (e.g. a new skill with title set)

However in this case as the urlid is set, but it is referencing a local resource that does not exist, I believe it should fail