Cht-conf create-users error: "Wrong type, object is not a place."

Describe the Bug
I’m trying to import some test users into my local development environment by following the steps in the documentation. When I run cht-conf, it reports it created 14 documents, but then shows an error.

How To Reproduce The Issue

  1. Create a CSV file called users.csv put it in csv folder. see below for raw CSV.
  2. Run the cht-conf command: cht csv-to-docs upload-docs create-users --url=https://medic:password@192-168-68-26.my.local-ip.co:8443
  3. See error: ERROR StatusCodeError: 400 - {"code":400,"error":"Wrong type, object is not a place."}

Expected Behavior
I should see 2 new user in the admin area, two new contacts and two new places. I see none of these. I do see a number of docs in fauxton (14 I’m guessing!)

Logs

cht csv-to-docs upload-docs create-users --url=https://medic:password@192-168-68-26.my.local-ip.co:8443
WARN No project package.json file found at /home/mrjones/Documents/MedicMobile/csv-to-docs/package.json 
WARN Project has no dependency on cht-conf. 
INFO Checking that https://medic:****@192-168-68-26.my.local-ip.co:8443/medic/ is available... 
INFO Processing config in csv-to-docs. 
INFO Actions:
     - csv-to-docs
     - upload-docs
     - create-users 
INFO Starting action: csv-to-docs… 
INFO Processing CSV file: /home/mrjones/Documents/MedicMobile/csv-to-docs/csv/users.csv … 
INFO Users csv has been saved 
INFO csv-to-docs complete. 
INFO Starting action: upload-docs… 
WARN This operation will permanently write 14 docs.  Are you sure you want to continue? 
Are you sure? [y/n]: y
14/14 docs 
INFO Summary: 14 of 14 docs uploaded OK.  Full report written to: upload-docs.1641510399181.log.json 
INFO upload-docs complete. 
INFO Starting action: create-users… 
INFO Creating user alice 
ERROR StatusCodeError: 400 - {"code":400,"error":"Wrong type, object  is not a place."}
    at new StatusCodeError (/usr/lib/node_modules/cht-conf/node_modules/request-promise-core/lib/errors.js:32:15)
    at Request.plumbing.callback (/usr/lib/node_modules/cht-conf/node_modules/request-promise-core/lib/plumbing.js:104:33)
    at Request.RP$callback [as _callback] (/usr/lib/node_modules/cht-conf/node_modules/request-promise-core/lib/plumbing.js:46:31)
    at Request.self.callback (/usr/lib/node_modules/cht-conf/node_modules/request/request.js:185:22)
    at Request.emit (events.js:400:28)
    at Request.<anonymous> (/usr/lib/node_modules/cht-conf/node_modules/request/request.js:1154:10)
    at Request.emit (events.js:400:28)
    at IncomingMessage.<anonymous> (/usr/lib/node_modules/cht-conf/node_modules/request/request.js:1076:12)
    at Object.onceWrapper (events.js:519:28)
    at IncomingMessage.emit (events.js:412:35)

Input CSV file:

username	password	roles	name	phone	contact.name	place.c_prop	place.type	place.name	place.parent
alice	Secret_1	chw	Alice Example	123456789	Alice	p_val_a	health_center	alice area	
bob	Secret_1	chw	bob Example	123456789	bob	p_val_a	health_center	bob area	

Error JSON file mentioned above:

cat upload-docs.1641510399181.log.json                                                                 
{
  "ok": [
    "043d963b-75fd-550c-a4b9-30adfa43917a",
    "0fc83157-873e-5d64-b064-a659d05f49fe",
    "1d042305-6aab-5b6b-be09-8eee96b4b510",
    "2403682f-8db3-5a15-ae78-0fcc4c20f5a4",
    "577b8637-49c0-5925-a58a-372710e83d09",
    "8a0a1987-dece-517c-bafa-43acb419cf20",
    "9f3ec000-6c9c-5369-a532-9a286b79173f",
    "a2e88124-37af-5886-8e7d-dd3d299f2cea",
    "a54f8772-0361-5717-92e9-67081eba082c",
    "b0700cc0-57f0-5847-91b9-31562f82c2ce",
    "b14ffab5-cf81-5bcb-acfe-6ac6b7e21e4b",
    "b20b4f67-25dc-51e8-a39b-43a6cd0ce7b5",
    "b870f528-617f-5075-9aa0-486da6611f45",
    "d74cb88b-0041-5b2f-a379-d029862b078d"
  ],
  "failed": {}
}

Environment

  • Instance: local dev
  • Browser: NA
  • Client platform: Ubuntu 20.04
  • App: cht-conf
  • Version: CHT Docker Helper with CHT 3.13 and cht-conf 3.9.4.

Additional Context
I noticed that pretty much no matter what CSV I use I get this error (like delete the place.type field for example). Also re-running the exact same command it reports “0 of 14 docs created” but then still shows the same error.

Hello @mrjones

I got the same error when I used the csv you provided without editing. The error indicates that the places provided for the users do not exist in your database. You can edit the csv to change the place properties (type, name, and parent) to a place that already exists or you can link to a place created in another csv doc.

Ah - interesting! I want to create new places though which the docs say is allowed. Does that mean I should remove the place.parent column when running the command?

Also I notice there’s two spaces in the error between “object” and “space” which maybe suggests the CHT was going to put something more in there? I could be reading between the lines too much though :wink:

Wrong type, object  is not a place.

I was hoping it would say something more helpful like a column name or row number there!

  • NB - the forum is removing the two spaces when it renders my text via inline code, so using a break out code box which adds extra, incorrect syntax highlighting :man_shrugging:

Testing some more, I’ve distilled the CSV to the bare minimum and still get the error (and real CSV this time, not TSV!):

username,password,roles,contact.name,place.type,place.name
alice,Secret_1,chw,Alice,health_center,alice area
bob,Secret_1,chw,bob,health_center,bob area

The docs say you only need these 5 columns:

The username, password, contact.name, place.type, place.name columns are required to have functional users with new places.

To link to places that are being created in another csv file you will need to have something like place:GET _id OF place WHERE reference_id=COL_VAL on the first line. You can see the documentation for this here.

1 Like

@njuguna - ah - ok - thank you! Looking closely I do see that the docs I originally cited, very much have a place.parent field and placeholder values of disctrict_uuid which I had ignored because I thought i could do it all from one CSV file. I see now that I need to use 3 CSV documents just as you demonstrated.

Thanks!