Add global bot and former global bot detection#79
Add global bot and former global bot detection#79Ezi-code wants to merge 8 commits intoWikimedia-Suomi:mainfrom
Conversation
Code Review - PR #79: Global Bot DetectionHi @Ezi-code! 👋 I've reviewed your implementation for adding global bot detection. Here's my detailed feedback: ✅ Strengths:
|
There was a problem hiding this comment.
I commented this but it seems that i left the comment pending without noticing it, sorry about that.
About the code : In any case it technically worked, but requesting global bot rights with every user was little bit slow and it would be faster to fetch all with single request.
- it should be now refactored latest main.
zache-fi
left a comment
There was a problem hiding this comment.
also python manage.py test reviews.tests.test_services fails after the changes
| ) | ||
|
|
||
| response = request.submit() | ||
| user_info = response.get("query", {}).get("globaluserinfo", {}) |
There was a problem hiding this comment.
Query returns "globalallusers" list and not globaluserinfo tms.
{'batchcomplete': '', 'limits': {'globalallusers': 500}, 'query': {'globalallusers': [{'id': 12943, 'name': 'Chobot', 'groups': ['global-bot'], 'existslocally': ''}, {'id': 13387278, 'name': 'Dexbot', 'groups': ['global-bot'], 'existslocally': ''}, {'id': 5195574, 'name': 'EmausBot', 'groups': ['global-bot'], 'existslocally': ''}, {'id': 44776378, 'name': 'InternetArchiveBot', 'groups': ['global-bot', 'oathauth-tester'], 'existslocally': ''}, {'id': 3114, 'name': 'JAnDbot', 'groups': ['global-bot'], 'existslocally': ''}, {'id': 6223, 'name': 'JhsBot', 'groups': ['global-bot'], 'existslocally': ''}, {'id': 53086278, 'name': 'KiranBOT', 'groups': ['global-bot'], 'existslocally': ''}, {'id': 54496224, 'name': 'Lingua Libre Bot', 'groups': ['global-bot'], 'existslocally': ''}, {'id': 28974611, 'name': 'Revibot', 'groups': ['global-bot', 'oathauth-tester'], 'existslocally': ''}, {'id': 583857, 'name': 'Xqbot', 'groups': ['global-bot'], 'existslocally': ''}, {'id': 27868374, 'name': 'YiFeiBot', 'groups': ['global-bot'], 'existslocally': ''}], 'userinfo': {'id': 1051277, 'name': 'Zache-test'}}}
| self.site = pywikibot.Site(code=wiki.code, fam=wiki.family) | ||
|
|
||
| @lru_cache(maxsize=1000) | ||
| def check_global_bot_user(self, username: str) -> tuple[bool, bool]: |
There was a problem hiding this comment.
I meant that it would do the slow API query only once and then it would use cached result. Now it it still makes one http query for every user even every time the result from http query is identical.
Thanks for the feedback. I was still working on the feature at the time. We experienced network disruptions in my region, so I pushed the code to GitHub. However, I have made the changes, and I am having a bit of a problem with the tests. I get an I'm stuck with that at the moment and would be glad if you could give me some pointers. |
@zache-fi, about the issues I was facing, I discovered something: In the This means that if the pattern for making requests changed, the test cases will expect us to explicitly define all the methods the low-level
I'm still trying to figure out how every component of the codebase works explicitly, but I think if we update the API call, we should acheive the same results. |
|
Yes, you can use simple requests for this |
# Conflicts: # app/reviews/autoreview.py # app/reviews/models.py # app/reviews/tests/test_autoreview.py # app/reviews/tests/test_services.py
Ok, just did. |
Description
This PR enhances the bot detection logic to recognize and auto-approve edits made by global bots and former global bots. This improves the accuracy of the autoreview process by correctly identifying legitimate automated edits from across the Wikimedia ecosystem.
Implementation Details:
Database Caching: Adds is_global_bot and is_former_global_bot fields to the EditorProfile model. This allows the bot status to be cached, avoiding redundant API calls and improving performance.
Service Layer: The ensure_editor_profile method in reviews/services.py now queries the Meta-Wiki API to fetch a user's global groups and updates the profile with their global bot status.
Autoreview Logic: The _is_bot_user function in autoreview.py has been updated to use these new database flags, ensuring that users identified as global or former global bots are approved.
Testing: Includes comprehensive unit tests to verify the new detection logic and ensure the changes are working as expected.
issue #6