API 2.0 user.delete not working or what 'id' is, is not clear
Description
Problem/Justification
None
Impact
None
SmartDraw Connector
Katalon Manual Tests (BETA)
Activity
Show:

Alex NA March 20, 2020 at 8:54 PM
After some more poking around i have come to figure out that the 'id' that user.delete wants is not the uid but an internal id.
I've found that i can figure out what this is by just calling user.query
Not Applicable
Pinned fields
Click on the next to a field label to start pinning.
Details
Details
Assignee

Reporter

Components
Fix versions
Affects versions
Priority
More fields
Time tracking
More fields
Time trackingKatalon Platform
Linked Test Cases, Katalon Defect Results, Katalon Studio Test Results
Katalon Platform
Linked Test Cases, Katalon Defect Results, Katalon Studio Test Results
Created March 19, 2020 at 5:46 PM
Updated July 1, 2022 at 4:50 PM
Resolved March 23, 2020 at 8:57 PM
I have been working my way though the new websocket API and i'm having an issue getting the user.delete method to work. The doc for this one would appear to say position 0 arg is 'id' i'm assuming this means uid since its the only 'id' i can find and username would be a string which is a type exception.
What i do:
Create a user:
<<<{"msg": "method", "id": "10", "method": "user.create", "params": [{"username": "foo", "full_name": "foo man", "password": "foo", "group_create": true}]}
>>>{"id": "10", "msg": "result", "result": 46}
This works, the user is in the UI etc.
Then i query to get the UID.
<<<{"msg": "method", "id": "11", "method": "user.get_user_obj", "params": [{"username": "foo"}]}
>>>{"id": "11", "msg": "result", "result": {"pw_name": "foo", "pw_uid": 1000, "pw_gid": 1000, "pw_gecos": "foo man", "pw_dir": "/nonexistent", "pw_shell": "/bin/csh"}}
This data matchs the UI, so far so good.
But then i try to delete the user
<<<{"msg": "method", "id": "12", "method": "user.delete", "params": [1000, {"delete_group": true}]}
>>>{"msg": "result", "id": "12", "error": {"error": 2, "type": "VALIDATION", "reason": "[ENOENT] None: User 1000 does not exist", "trace": {"class": "ValidationError", "frames": [{"filename": "/usr/local/lib/python3.7/site-packages/middlewared/main.py", "lineno": 150, "method": "call_method", "line": " (e.attribute, e.errmsg, e.errno),\n", "argspec": ["self", "message", "serviceobj", "methodobj"], "locals": {"self": "<middlewared.main.Application object at 0x8318a1110>", "message": "{'msg': 'method', 'id': '12', 'method': 'user.delete', 'params': [1000, {'delete_group': True}]}", "serviceobj": "<middlewared.plugins.account.UserService object at 0x80e14cf10>", "methodobj": "<bound method CRUDService.delete of <middlewared.plugins.account.UserService object at 0x80e14cf10>>", "params": "[1000, {'delete_group': True}]", "e": "ValidationError(None, 'User 1000 does not exist', 2)"}}, {"filename": "/usr/local/lib/python3.7/site-packages/middlewared/main.py", "lineno": 1077, "method": "_call", "line": " return await methodobj(*args)\n", "argspec": ["self", "name", "serviceobj", "methodobj", "params", "app", "pipes", "job_on_progress_cb", "io_thread"], "locals": {"self": "<middlewared.main.Middleware object at 0x80d84ac90>", "name": "'user.delete'", "serviceobj": "<middlewared.plugins.account.UserService object at 0x80e14cf10>", "methodobj": "<bound method CRUDService.delete of <middlewared.plugins.account.UserService object at 0x80e14cf10>>", "params": "[1000, {'delete_group': True}]", "app": "<middlewared.main.Application object at 0x8318a1110>", "pipes": "None", "job_on_progress_cb": "None", "io_thread": "False", "args": "[1000, {'delete_group': True}]", "job_options": "None", "job": "None"}}, {"filename": "/usr/local/lib/python3.7/site-packages/middlewared/service.py", "lineno":
410, "method": "delete", "line": " f'{self._config.namespace}.delete', self, self.do_delete, [id] + list(args)\n", "argspec": ["self", "id"], "varargspec": "args", "locals": {"self": "<middlewared.plugins.account.UserService object at 0x80e14cf10>", "id": "1000", "args": "('***',)"}}, {"filename": "/usr/local/lib/python3.7/site-packages/middlewared/main.py", "lineno": 1077, "method": "_call", "line": " return await methodobj(*args)\n", "argspec": ["self", "name", "serviceobj", "methodobj", "params", "app", "pipes", "job_on_progress_cb", "io_thread"], "locals": {"self": "<middlewared.main.Middleware object at 0x80d84ac90>", "name": "'user.delete'", "serviceobj": "<middlewared.plugins.account.UserService object at 0x80e14cf10>", "methodobj": "<bound method accepts.<locals>.wrap.<locals>.nf of <middlewared.plugins.account.UserService object at 0x80e14cf10>>", "params": "[1000, {'delete_group': True}]", "app": "None", "pipes": "None", "job_on_progress_cb": "None", "io_thread": "True", "args": "[1000, {'delete_group': True}]", "job_options": "None", "job": "None"}}, {"filename": "/usr/local/lib/python3.7/site-packages/middlewared/schema.py", "lineno": 961, "method": "nf", "line": "
return await f(*args, *kwargs)\n", "varargspec": "args", "keywordspec": "kwargs", "locals": {"args": "('*', '*', '**')", "kwargs": "{}", "clean_and_validate_args": "<function accepts.<locals>.wrap.<locals>.clean_and_validate_args at 0x80e1b5710>", "f": "<function UserService.do_delete at 0x80e1b5680>"}}, {"filename": "/usr/local/lib/python3.7/site-packages/middlewared/plugins/account.py", "lineno": 441, "method": "do_delete", "line": " user = await self._get_instance(pk)\n", "argspec": ["self", "pk", "options"], "locals": {"self": "<middlewared.plugins.account.UserService object
at 0x80e14cf10>", "pk": "1000", "options": "{'delete_group': True}"}}, {"filename": "/usr/local/lib/python3.7/site-packages/middlewared/service.py", "lineno": 421, "method": "_get_instance", "line": "
raise ValidationError(None, f'{self._config.verbose_name} {id} does not exist', errno.ENOENT)\n", "argspec": ["self", "id"], "locals": {"self": "<middlewared.plugins.account.UserService object at
0x80e14cf10>", "id": "1000", "instance": "[]"}}], "formatted": "Traceback (most recent call last):\n File \"/usr/local/lib/python3.7/site-packages/middlewared/main.py\", line 130, in call_method\n io_thread=False)\n File \"/usr/local/lib/python3.7/site-packages/middlewared/main.py\", line 1077, in _call\n return await methodobj(*args)\n File \"/usr/local/lib/python3.7/site-packages/middlewared/service.py\", line 410, in delete\n f'{self._config.namespace}.delete', self, self.do_delete, [id] + list(args)\n File \"/usr/local/lib/python3.7/site-packages/middlewared/main.py\", line 1077, in _call\n return await methodobj(*args)\n File \"/usr/local/lib/python3.7/site-packages/middlewared/schema.py\", line 961, in nf\n return await f(*args, **kwargs)\n File \"/usr/local/lib/python3.7/site-packages/middlewared/plugins/account.py\", line 441, in do_delete\n user = await self._get_instance(pk)\n File \"/usr/local/lib/python3.7/site-packages/middlewared/service.py\", line 421, in _get_instance\n raise ValidationError(None, f'{self._config.verbose_name} {id} does not exist', errno.ENOENT)\nmiddlewared.service_exception.ValidationError: [ENOENT] None: User 1000 does not exist\n"}, "extra": [[null, "User 1000 does not exist", 2]]}}
Error is User 1000 does not exist.
I've tried arbitray delays thinking i just try too soon after creating based on the comment in user.get_user_obj about a user cache to no effect.
I've also tried using the string username which failed type validation (no suprise).