Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Users.all() does not return all users #327

Closed
misilot opened this issue Aug 8, 2023 · 4 comments
Closed

Bug: Users.all() does not return all users #327

misilot opened this issue Aug 8, 2023 · 4 comments
Assignees
Labels

Comments

@misilot
Copy link
Contributor

misilot commented Aug 8, 2023

https://python-redmine.com/resources/user.html#all does not appear to return all users. It only returns the active users. It does not include the registered or locked users.

I am trying to search for users to update their accounts from a third party system if they are in an external group, and reactive them. However since all() does not return everyone, it tries to create them instead of trying to unlock and then update them.

Thanks!

@maxtepkeev maxtepkeev self-assigned this Aug 10, 2023
@maxtepkeev
Copy link
Owner

As a quick fix you can use redmine.user.filter(status='') i.e. supply empty value to get all users regardless of their status. Right now redmine.user.all() returns just active users because back in the days Redmine API wasn't able to return all statuses, i.e. it didn't support this empty value hack I mentioned above. And when they finally introduced it I completely forgot to add it to a redmine.user.all() method by default, so thanks for reminding me about it, I'll introduce a fix in the next version.

@misilot
Copy link
Contributor Author

misilot commented Aug 10, 2023

Thanks!

I don't think that will help me at least. Since, it doesn't return the status unfortunately. So I think I am stuck doing two requests and combining / adding a status field.

@maxtepkeev
Copy link
Owner

maxtepkeev commented Aug 10, 2023

Ah yes, you're right, if you need a status property then you have to make a separate request for each user anyway which isn't optimal and very slow, but that's what we get with current Redmine API.

The only thing I would mention is a refresh() method on a resource (user resource in your case) which will basically do a single request and add a status property (and other missing properties if any) to a current user resource, so you won't have to do that manually and combine different results afterwards, i.e.:

users = redmine.user.filter(status='')

for user in users:
    user.refresh()    # this is an equivalent of redmine.user.get(user.id), you can also do a u = user.refresh(itself=False) if you want to get a copy of a user resource in another variable
    print(user.status)

@maxtepkeev
Copy link
Owner

Fixed in cece6b4

maxtepkeev added a commit that referenced this issue Mar 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants