1. What is the issue? Please be detailed.
When uploading Entities via pyODK it is not possible to upload another copy of a CSV if it includes a pre-defined __id / uuid column for the entity. Even in a separate Project. Or after the entities have been deleted.
I suppose this is logical and SHOULD be expected, I just didn't anticipate it being 'site-wide' or include entities in Trash.
In my case I am generating the CSV from QuODK and it includes a UUID so that it is linked to the feature within QGIS...
2. What steps can we take to reproduce this issue?
Create a CSV with a column __id (or any other name an refer to it as the uuid). Upload it to Central.
Use the script below (adapted from the pyODK docs). The entity list is created and populated correctly. The linked form can update and create entities within this list.
from pyodk.client import Client
from csv import DictReader
from pathlib import Path
projectId = 3
listname="mylist"
csv_path = "path/to/my.csv"
entity_label_field = "label"
entity_properties = ("geometry", "Type", "Notes", "length", "stroke")
eid = "__id" # This is the uuid field for the entity
with Client(project_id=projectId) as client, open(csv_path) as csv_file:
entity_list = client.entity_lists.create(entity_list_name=listname)
for prop in entity_properties:
client.entity_lists.add_property(name=prop, entity_list_name=listname)
for row in DictReader(csv_file):
client.entities.create(
label=row[entity_label_field],
uuid = row[eid],
data={k: str(v) for k, v in row.items() if k in entity_properties},
entity_list_name=listname,
)
Then, go to a different project (in my case projectId = 6) and repeat... The entity list is created but the upload of entities fails (this is the second error I encountered - I tried deleting the entities, but they are sitting in the Trash, so are still technically on the server):
PyODKError: ('The request to https://mycentralserver/v1/projects/6/datasets/mylist/entities failed. Status: 409, content: {"message":"The following UUID(s) cannot be used because they are associated with deleted Entities: (baabe091-cd2f-4469-a3ed-797ddf24bf45).","code":409.19,"details":{"entityUuids":["baabe091-cd2f-4469-a3ed-797ddf24bf45"]}}', <Response [409]>)
3. What have you tried to fix the issue?
As above, deleted the entities in the other entity list.
I haven't waited 30 days for the trash purge (impatient, I know, sorry!) and have not manually purged.
I can work around this by omitting / commenting out uuid = row[eid]
(I confirm that this works) - but this breaks the link to QGIS as the entities have a new uuid that has been generated by Central.
There may not be a 'solution' except manual purging of Trash, but I thought it might be helpful to document my heuristics (mostly Error, and plenty of Trial) - in case it saves blushes for anyone else.
I will update the script to include an option to remove the pre-defined uuid.