HumanSignal/label-studio-sdk

get_users() validation error

denck007 opened this issue · 5 comments

Using latest label studio docker image and latest sdk, I get an error when running the user_management.ipynb example. I started the server, manually created my account and project, then tried to use the API to get my user info. I am able to run the examples on the tutorial page

Running:

import label_studio_sdk
ls = label_studio_sdk.Client('http://localhost:8080', api_key='my_api_key')
users = ls.get_users()
for user in users:
    print(user.id, user.email)

Results in:

---------------------------------------------------------------------------
ValidationError                           Traceback (most recent call last)
/tmp/ipykernel_6487/3424670844.py in <module>
----> 1 users = ls.get_users()
      2 for user in users:
      3     print(user.id, user.email)

~/anaconda3/envs/ls14/lib/python3.9/site-packages/label_studio_sdk/client.py in get_users(self)
    119         for user_data in response.json():
    120             user_data['client'] = self
--> 121             users.append(User(**user_data))
    122         return users
    123 

~/anaconda3/envs/ls14/lib/python3.9/site-packages/pydantic/main.cpython-39-x86_64-linux-gnu.so in pydantic.main.BaseModel.__init__()

ValidationError: 1 validation error for User
org_membership
  field required (type=value_error.missing)

The API appears to return reasonable values:

requests.get("http://localhost:8080/api/users", headers={"Authorization": f"token {API_KEY}"}).json()
[{'id': 1,
  'first_name': '',
  'last_name': '',
  'username': 'test user',
  'email': 'test_user@test.com',
  'last_activity': '2021-12-23T19:32:40.155569Z',
  'avatar': None,
  'initials': 'tu',
  'phone': '',
  'active_organization': 1}]

Looks like the User.org_membership is required in the SDK but is not returned by the API. I looked at label_studio/users/serializers.py and label_studio/users/models.py and there doesn't seem to be any reference to org_membership there.

SDK version

label_studio_sdk.__version__
'0.0.6'

Server info

{
  "release": "1.4",
  "label-studio-os-package": {
    "version": "1.4",
    "short_version": "1.4",
    "latest_version_from_pypi": "1.4",
    "latest_version_upload_time": "2021-11-19T15:56:02",
    "current_version_is_outdated": false
  },

  "label-studio-os-backend": {
    "message": "Fix for issues/1859 (#1868)",
    "commit": "a2532d471fa8e2ac33ac51b08b711b6973ac3881",
    "date": "2021-12-23 10:27:32 +0400",
    "branch": "master",
    "version": "1.4.0+63.ga2532d4.dirty"
  },

  "label-studio-frontend": {
    "message": "DEV-1312: Fix relations restoration (#389)  * Fix regions tree assembl ...",
    "commit": "d886b810bae4ee0bff3bac884838cae2c1b6f8aa",
    "branch": "master",
    "date": "2021-12-13T15:40:57Z"
  },

  "dm2": {
    "message": "DEV-609: Load task data from server (#22)  * Load task data from serve ...",
    "commit": "feb9f1db923039b098fd0122f3d6a87bdc224a79",
    "branch": "master",
    "date": "2021-11-18T20:01:55Z"
  },

  "label-studio-converter": {
    "version": "0.0.37"
  }
}

@denck007 Could you try to use SDK installed from github instead of pypi?

I ran pip uninstall label-studio-sdk then pip install git+https://github.com/heartexlabs/label-studio-sdk.git. Then restarted the kernel on user_management.ipynb and am getting the same error.

@denck007 I think the problem is because you are using community version of LS, but it works only with LS enterprise (this example is in the label_studio_enterprise folder).

Thanks @makseq, at least there is a reason it didn't work. Is there a way to get all the users in the community edition? The docs for User and docs for Client.get_users() don't mention that it is enterprise only.

Would it make sense to change org_membership: List[OrgMembership] to org_membership: Optional[List[OrgMembership]] or org_membership: List[Optional[OrgMembership]]? Another option could be to have the client detect what type of server is running when the client is created, then do something like User = UserEnterprise if self.enterprise_server else UserCommunity.

What are your thoughts on doing something like this?

@denck007 sure, list of users must be accessible with all LS editions, we need to fix it. Could you contribute?