Issue644

Title 'Random Issue' Button isn't working
Priority bug Status chatting
Superseder Nosy List berker.peksag, csabella, ezio.melotti, rouilj
Assigned To Topics

Created on 2017-10-23.23:58:33 by csabella, last changed 2017-11-11.21:03:43 by rouilj.

Messages
msg3407 (view) Author: csabella Date: 2017-10-23.23:58:32
The 'Random Issue' button used to show a new issue every time it was clicked, but for the past few weeks, the issue returned only changes once a day.
msg3414 (view) Author: berker.peksag Date: 2017-11-05.15:57:28
From http://www.roundup-tracker.org/docs/customizing.html#extensions-adding-capabilities-to-your-tracker

    All files from this dir are loaded when tracker instance is created, [...]

It's not clear to me when this was added, but it seems like this is the cause of the bug.

I added a global counter in pydevutils.py to test this and it didn't work.

Ezio, is there a way to solve this bug?
msg3415 (view) Author: berker.peksag Date: 2017-11-09.19:54:47
Hi John, do you know a workaround to make the random issue extension work again?
msg3417 (view) Author: rouilj Date: 2017-11-11.02:59:39
Hi Berker:

In message <1510257288.61.0.213398074469.issue644@psf.upfronthosting.co.za>,
Berker Peksag writes:
>Hi John, do you know a workaround to make the random issue
>extension work again?

I pulled the source for the bugs.python.org tracker and took a look.

The function I got to work better in my demo tracker was:

import random
from roundup.cgi.actions import Action
from roundup.cgi.exceptions import Redirect

class RandomIssueAction(Action):
    def handle(self):
        """Redirect to a random open issue."""
        issue = self.db.getclass('issue')
        issue_ids = issue.filter(None, {'status': 1})
        random.seed()
	url = self.db.config.TRACKER_WEB + 'issue' + random.choice(issue_ids)
        raise Redirect(url)

def init(instance):
    instance.registerAction('random', RandomIssueAction)

I changed:

   the way I got the handle to issues from the db
   the way the list of id's in my tracker instance

I was getting tracebacks otherwise. Since you do get redirected to a
page on bugs.python.org you obviously aren't getting traceback so this
new function may not work.

Originally triggering the random action I saw a lot of repeats. My
thought was that the random function wasn't so random. The new 1.5.1+
(what will be 1.6) roundup uses more random data than 1.4.20. Addition
of nonces to protect against csrf etc. consumes random data.

So I added random.seed(). This seemed to increase the randomness of the
function. You may want to try adding random.seed() to your existing
function and see if that helps.

Even after seeding, I still saw duplicates, but there were only 20
issues to choose from. In your case you have 6000+ issues to select
from duplicates by chance are reduced.
msg3418 (view) Author: berker.peksag Date: 2017-11-11.05:05:04
Thank you for your quick response and for your detailed analysis, John.

I will attach a patch to implement your suggestions.

> My thought was that the random function wasn't so random. The new 1.5.1+
> (what will be 1.6) roundup uses more random data than 1.4.20. Addition
> of nonces to protect against csrf etc. consumes random data.

Should I open an upstream issue to document this at http://roundup.sourceforge.net/docs/upgrading.html ?
msg3419 (view) Author: rouilj Date: 2017-11-11.15:32:03
Hello Berker:

In message <1510376704.3.0.213398074469.issue644@psf.upfronthosting.co.za>,
Berker Peksag writes:
>Thank you for your quick response and for your detailed analysis, John.
>
>I will attach a patch to implement your suggestions.
>
>> My thought was that the random function wasn't so random. The new 1.5.1+
>> (what will be 1.6) roundup uses more random data than 1.4.20. Addition
>> of nonces to protect against csrf etc. consumes random data.
>
>Should I open an upstream issue to document this at
> http://roundup.sourceforge.net/docs/upgrading.html ?

Can you try my patch with and without the random.seed() call and see
if it makes a difference on bugs.python.org.

If the patch without random.seed() works then there is something
different happening on the b.p.o tracker and my test tracker.

As I said the code I got from your tracker wouldn't run at all in my
installation (context was always None, _klass wasn't a valid property
etc.). Given that I had to do surgery to even make it not crash I
wonder if there is something else in the code base that I am missing.

How the b.p.o tracker executed?  I run roundup as a stand alone
daemon with a web server front end proxying to the roundup
instance. How is b.p.o configured?  CGI, stand alone daemon, wsgi,
mod_python, zope?

I wonder if that makes a difference.
msg3420 (view) Author: rouilj Date: 2017-11-11.21:03:42
Hi all:

In message <20171111153201.827854C03FF@itserver6.localdomain>,
John Rouillard writes:
>In message <1510376704.3.0.213398074469.issue644@psf.upfronthosting.co.za>,
>Berker Peksag writes:
>>Thank you for your quick response and for your detailed analysis, John.

Well it gets more wierd.

>>I will attach a patch to implement your suggestions.
>>
>>> My thought was that the random function wasn't so random. The new 1.5.1+
>>> (what will be 1.6) roundup uses more random data than 1.4.20. Addition
>>> of nonces to protect against csrf etc. consumes random data.
>>
>>Should I open an upstream issue to document this at
>> http://roundup.sourceforge.net/docs/upgrading.html ?

Hmm, seems roundup is borking something in the random module.

I created a default tracker using ./demo.py in a current checkout of
the roundup tree.

I added 30 issues and my implementation of your random action.
I also added: 

   print random.random()
   print random.random()

inside the handler. I get the same sequence every time:

  0.8774733181
  0.652775856602

I access the http://...?@action=randomurl. That's not right

Every import of random is supposed to be seeded with the current time
or some os specific random data every time. Then once it's seeded the
same instance of random should be updating the random state so the
next call to random produces the next random number.

AFAICT, what I see should be happening only if something in the code
is calling random.seed() with the same value every time the url is
accessed.

However even when I comment out all of the seed() calls in the roundup
code (all located in roundup/cgi/client.py) I get the same results as
above. So there are no calls to random.seed in the roundup code base.

Restarting the server by rerunning ./demo.py generates a new
sequence with different values.

Shoving a random.seed() in the handler function is merely covering up
something that is broke.

I'll keep poking at it to try to figure out why random seems to be
losing state, but I am stumped here.
History
Date User Action Args
2017-11-11 21:03:43rouiljsetmessages: + msg3420
2017-11-11 15:32:03rouiljsetmessages: + msg3419
2017-11-11 05:05:04berker.peksagsetmessages: + msg3418
2017-11-11 02:59:40rouiljsetmessages: + msg3417
2017-11-09 19:54:48berker.peksagsetnosy: + rouilj
messages: + msg3415
2017-11-05 15:57:29berker.peksagsetstatus: unread -> chatting
nosy: + berker.peksag, ezio.melotti
messages: + msg3414
2017-10-23 23:58:33csabellacreate