Page MenuHomePhabricator

MediaWiki.get_content should return something meaningful fetching non-existent page
Closed, ResolvedPublic

Description

(pyenv) urbanecm@notebook ~/unsynced/git/wmf/gerrit/wikimedia-cz/tracker/trackersite 
$ ./manage.py shell
Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15) 
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.contrib.auth.models import User
>>> from socialauth.api import MediaWiki
>>> mw = MediaWiki(User.objects.get(username="urbanecm"), "https://commons.wikimedia.org/w/api.php")
>>> mw.get_content("This does not exist for sure")
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/urbanecm/unsynced/git/wmf/gerrit/wikimedia-cz/tracker/trackersite/socialauth/api.py", line 51, in get_content
    return data[data.keys()[0]]["revisions"][0]["slots"][rvslot]["*"]
KeyError: 'revisions'
>>> 
(pyenv) urbanecm@notebook ~/unsynced/git/wmf/gerrit/wikimedia-cz/tracker/trackersite 
$

Possible outputs: None, custom exeption?

Event Timeline

Urbanecm created this task.Dec 11 2018, 9:29 AM
Urbanecm triaged this task as Lowest priority.Jan 18 2019, 6:56 PM
Urbanecm added a project: good first bug.

Hi @Urbanecm. I have doubts about this task and T213173. I searched the socialauth package and I only find its documentation page and all its related stuff (PyPI, GitHub, etcetera). It isn't seem to be related or developed for Wikimedia projects, nor nothing tracked here. And the most strange is that I don't understand where is the MediaWiki method you are using, because it isn't in authentication.py neither in other files.

I install this package and when I try from socialauth.api import MediaWiki I get a ModuleNotFoundError. I just can to import socialauth.

Could you confirm this package is the one you are using? If not, where do you download it?

Hi @Ivanhercaz, thanks for commenting here! Your confusion comes from ambiguity between socialauth package (developped outside Wikimedia) and socialauth Django app, a part of Tracker's codebase (wikimedia-cz/tracker in Gerrit). If you inspect trackersite/socialauth/api.py, you'll see the methods I refer to.

You can import and use this module from Django shell, which you can invoke using python manage.py shell in trackersite directory, see task's description.

Ivanhercaz added a comment.EditedFeb 9 2019, 5:30 PM

You're welcome @Urbanecm!

Your confusion comes from ambiguity between socialauth package (developped outside Wikimedia) and socialauth Django app, a part of Tracker's codebase...

All right! Now everything has sense, thank you! I didn't note the tag WMCZ-Tracker. All right, I am going to review the code and try to help you with this task. What you want seems easy, because is to have a custom exception for this case. As I am new contributing to projects in Gerrit I am going to read fine all the Gerrit's documentation, the developer guide and whatever I see necessary to do all my best with my first contrib to Wikimedia repositories.

Thanks for working on this. If you have further questions, feel free to ask here.

@Urbanecm, what about a message like this one:

>>> mw.get_content("content that not exists")
The requested content doesnt't exist.

@Ivanhercaz Sorry so much for not replying, I must've missed this question. It looks to me that you're using a print statement. That's big no-no for any other purpose than local debug. It should be either a specific return value meaning "no articles" (probably None), or a custom exception that describes the problem (maybe using your sentence, that's not a problem). Does this answer your question?

@Ivanhercaz Hi, how are you? Do you need to know anything else? May I help you to complete this task?

Change 508966 had a related patch set uploaded (by Ivanhercaz; owner: Ivanhercaz):
[wikimedia-cz/tracker@master] Add custom exception in get_content

https://gerrit.wikimedia.org/r/508966

@Urbanecm, this is my first contribution to Gerrit, so I hope I have done everything correctly.

Change 510275 had a related patch set uploaded (by Ivanhercaz; owner: Ivanhercaz):
[wikimedia-cz/tracker@master] Change the try/except block for an if statement

https://gerrit.wikimedia.org/r/510275

Change 510275 abandoned by Ivanhercaz:
Change the try/except block for an if statement

Reason:
abandoning in favor of https://gerrit.wikimedia.org/r/c/wikimedia-cz/tracker/ /508966

https://gerrit.wikimedia.org/r/510275

Change 508966 merged by jenkins-bot:
[wikimedia-cz/tracker@master] Add custom exception in get_content

https://gerrit.wikimedia.org/r/508966

Urbanecm closed this task as Resolved.May 15 2019, 10:38 AM