#✅ createUser return RECORD_NOT_UNIQUE

1 messages · Page 1 of 1 (latest)

lime widget
#

Hello Guys, I am using the new sdk in order to create some users for my application, currently my postgres database contains only One admin user .
I am running this script :
if (!user) { await directusClient.request( createUser({ first_name: userConfig.first_name, description: userConfig.description, token: userConfig.token, role: role.id }) ).catch(err => console.log(JSON.stringify(err))); }
and It returns me this :

{"errors":[{"message":"Value for field "id" in collection "directus_users" has to be unique.","extensions":{"code":"RECORD_NOT_UNIQUE","collection":"directus_users","field":"id"}}]}

So far I have been able to utilise all the methods like createItem, or createRole , but this particular one breaks

next spireBOT
#

Thanks for posting! This is a community powered server, so you may or may not get an answer based on available help and expertise. To increase your chances of somebody being able to help you, please help us help you making sure you:

  • Adding an explanation of exactly what you're trying to achieve.
  • Adding any and all related code or previous attempts.
  • Describing the exact issue or error you are facing.
  • Posting any screenshots if applicable.
  • Reading through https://stackoverflow.com/help/how-to-ask.

When you're done with this thread, please close it. Thanks! ✨

(If you have a support agreement and need help, please contact the core team via email.)

ancient bay
#

The error is a bit strange 🤔 but it looks like you're missing the unique field email when creating a user likely resulting in the unique constraint failing because there is already a user without email created

lime widget
#

hm so email is required now ? I am refactoring from the old sdk and email wasn't required, will check that

ancient bay
#

unrelated to the SDK but while email is not required as such it is still expected to be unique so you can only ahve a single user without email.

#

Nothing changed there recently as far as im aware

lime widget
#

just notised that currently in my localhost it also prevents me from create a user even from the ui. So probably not a problem of the createUser command , but something else I guess. Will investigate further and come back if i have anything more to add. Thanks a lot

ancient bay
#

No indeed this is how the API/Database works not much the SDK can do about that

lime widget
#

Hello again @ancient bay , I have noticed that I receive this upon running my docker container

[14:04:45.356] DEBUG: Invalid user credentials.
err: {
"type": "",
"message": "Invalid user credentials.",
"stack":
DirectusError: Invalid user credentials.
at getAccountabilityForToken (file:///directus/node_modules/.pnpm/file+api/node_modules/@directus/api/dist/utils/get-accountability-for-token.js:41:23)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async handler (file:///directus/node_modules/.pnpm/file+api/node_modules/@directus/api/dist/middleware/authenticate.js:36:26)
"name": "DirectusError",
"code": "INVALID_CREDENTIALS",
"status": 401
}

#

this wasn't happening before updating to 10.5.2 (previusly on 10.4.3)

ancient bay
#

without more context i can only assume something is trying to login with invalid credentials 🤷‍♂️

lime widget
#

Yeah nevermind, sorry about that I know why it happens , this is happening because I haven't created the users I mentioned. So my other services fail to connect

lime widget
#

What I am realizing is that a lot of this are broken, Let me give you a better example this time. I have a collection Artist, that use an auto_increment id as primary key here is the yaml of this : collection: Artist field: id type: integer meta: collection: Artist conditions: null display: null display_options: null field: id group: null hidden: true interface: input note: null options: null readonly: true required: false sort: 1 special: null translations: null validation: null validation_message: null width: full schema: name: id table: Artist data_type: integer default_value: nextval('"Artist_id_seq"'::regclass) max_length: null numeric_precision: 32 numeric_scale: 0 is_nullable: false is_unique: true is_primary_key: true is_generated: false generation_expression: null has_auto_increment: true foreign_key_table: null foreign_key_column: null

#

Upon creating a new artist on version 10.5.2 i get this : insert into "Artist" ("connections_count", "date_created", "id", "organization", "status", "user_created") values ($1, $2, $3, $4, $5, $6) returning "id" - invalid input syntax for type integer: "d2f63273-531e-4b62-b0b7-b6007a7d6e2c"",

#

although if I create a new collection again with id an integer, i will be able to crete a new entry successfully

ancient bay
#

Thats strange, for a table you created using the App?

lime widget
#

originaly Artist was created through the ap , but now i import it to the app by importing the snapshot.yaml

ancient bay
#

What does the API response look like when fetching that ID field? judging from the error i would expect meta.special: ['uuid'] to be set as that would trigger directus to generate an uuid

lime widget
#

Sorry if this a sily answer but not sure what you mean, when I fetch this. I do not set meta.special anywhere in my code

ancient bay
lime widget
#

got you, it returns this : { "data": { "collection": "Artist", "field": "id", "type": "integer", "meta": { "id": 23, "collection": "Artist", "field": "id", "special": null, "interface": "input", "options": null, "display": null, "display_options": null, "readonly": true, "hidden": true, "sort": 1, "width": "full", "translations": null, "note": null, "conditions": null, "required": false, "group": null, "validation": null, "validation_message": null }, "schema": { "name": "id", "table": "Artist", "schema": "public", "data_type": "integer", "is_nullable": false, "generation_expression": null, "default_value": "nextval('\"Artist_id_seq\"'::regclass)", "is_generated": false, "max_length": null, "comment": null, "numeric_precision": 32, "numeric_scale": 0, "is_unique": true, "is_primary_key": true, "has_auto_increment": true, "foreign_key_schema": null, "foreign_key_table": null, "foreign_key_column": null } } }

ancient bay
#

Hmmm

#

So that seems just like a regular auto increment config so there is no reason for Directus to be adding a UUID to the object 🤔

#

Only alternative i can think of is that you're already providing this UUID value when creating the item maybe?

lime widget
#

hello again first of all sorry for your time, just an fyi, I realised that this error occured due to a missconfiguration , when a directus flow is triggered. On start up I also import some flows for my app. that had a bug. Errors where a bit missleading tbh. Thank you for your time again,I will procceed on closing this thread

next spireBOT
#

✅ createUser return RECORD_NOT_UNIQUE