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

User sync removes already existing users #343

Closed
pavanfhw opened this issue Mar 8, 2021 · 4 comments · Fixed by #345
Closed

User sync removes already existing users #343

pavanfhw opened this issue Mar 8, 2021 · 4 comments · Fixed by #345

Comments

@pavanfhw
Copy link

pavanfhw commented Mar 8, 2021

I think this is a misconfiguration on my part, but every loop of the oncall-user-sync it get the users from LDAP server and tries to add them to the database. But if the user already exists it gives the error for each user:
(1062, "Duplicate entry '<my user on ldap server>' for key 'user.username_unique'")

And then the users gets removed from the database (also its contacts etc). The next iteration it inserts all the users present in the LDAP server. Next time it removes them again for the same reason given above. This does not make sense. I am not being able to understand why it is happening. Can someone give correct configuration example for this features?

@altaroinj
Copy link

I had the same issue when trying to use oncall.
After investigation, when retrieving users from ldap, username seems to be stored as byte instead of string.
So when users to delete are determined (inactive_users = oncall_usernames - ldap_usernames in ldap_sync.py script), both sets are not in the same format.
To avoid this, I just added this line :
username = username.decode()
just before this one in fetch_ldap() method :
contacts = {'call': mobile, 'sms': mobile, 'email': mail, 'slack': slack, 'name': name}

I am no expert in Python langage, so maybe my solution is not the best, or even breaks something else.
I'll let oncall devs validate it.

@pavanfhw
Copy link
Author

pavanfhw commented Mar 10, 2021

Hello @altaroin, thanks for the explanation. I reached the same solution.
My diff in ldap_sync.py is:

-            users[username] = contacts
+            users[username.decode("utf-8")] = contacts

For people with this issue in the future, the issues is caused by the problem explained by @altaroinj. The simple solution is to decode the user like in his (or mine) code example.

@diegocepedaw
Copy link
Contributor

@altaroinj or @pavanfhw, could either of you validate if this change fixes your issue? Internally we use a different custom sync script but I want to make sure the current code is not broken for those that are using the existing ldap sync diegocepedaw@f61fad1

@diegocepedaw diegocepedaw reopened this Mar 10, 2021
@altaroinj
Copy link

@diegocepedaw, I can you confirm that it solved the problem.

@diegocepedaw diegocepedaw linked a pull request Mar 10, 2021 that will close this issue
@jwon jwon closed this as completed in #345 Mar 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants