How to add things to the `created_resources` list of a task

When uploading a package using the repository parameter using:

${HTTP_CMD} --form post ${PULP_URL}/pulp/api/v3/content/deb/packages/ file@../frigg_1.0_ppc64.deb repository=${REPOSITORY_HREF}

We get the following Task:

{
  "pulp_href": "/pulp/api/v3/tasks/cc564084-002e-4468-885c-31c2739a959e/",
  "pulp_created": "2023-04-20T09:44:31.806989Z",
  "state": "completed",
  "name": "pulpcore.app.tasks.base.general_create",
  "logging_cid": "efd74e434bda4dd48a1629dade0f24fd",
  "started_at": "2023-04-20T09:44:31.958019Z",
  "finished_at": "2023-04-20T09:44:33.697890Z",
  "error": null,
  "worker": "/pulp/api/v3/workers/46a9999d-ea88-4ecc-80c4-49662e7ba352/",
  "parent_task": null,
  "child_tasks": [],
  "task_group": null,
  "progress_reports": [],
  "created_resources": [
    "/pulp/api/v3/repositories/deb/apt/7b64a63c-d7a3-4157-a489-4b52dc1c6e12/versions/1/",
    "/pulp/api/v3/content/deb/packages/89372ce4-1a0b-4fca-9b76-f4d595704d14/"
  ],
  "reserved_resources_record": [
    "/pulp/api/v3/repositories/deb/apt/7b64a63c-d7a3-4157-a489-4b52dc1c6e12/"
  ]
}

With this PR we have modified the behaviour of our serializer to additionally also create a ReleaseComponent and PackageReleaseComponent. However, these do not appear in the list of created_resources, since the Task does not know about them.

My question is: Is there a way of creating additional entities in a serializer, that will make those entities appear in the created_resources list?

It all boils down to creating a db record for it:

resource = CreatedResource(content_object=instance)
resource.save()
2 Likes