Page 1 of 1

ParametersI buggy in Python

PostPosted: Wed Aug 04, 2010 12:02 pm
by bernhard
Hi folks!

There seems to be a bug with the implementation of ParametersI in python. Seems there just one object created in the global scope, like a singleton. Here's an example:

Code: Select all

from omero_sys_ParametersI import ParametersI

def foo():
    params_foo = ParametersI().addLong('foo', 1)
    print "********** Params in foo **********"
    print params_foo

if __name__ == "__main__":

    foo()
    params = ParametersI()
    params.addLong('bar', 2)

    params2 = ParametersI()
    params2.addLong('foobar', 3)

    print "********** Params in main **********"
    print params2


The output looks like this:
Code: Select all

********** Params in foo **********
object #0 (::omero::sys::Parameters)
{
    map =
    {
        key = foo
        value = object #1 (::omero::RLong)
        {
            _val = 1
        }
    }
    theFilter = <nil>
    theOptions = <nil>
}
********** Params in main **********
object #0 (::omero::sys::Parameters)
{
    map =
    {
        key = foobar
        value = object #1 (::omero::RLong)
        {
            _val = 3
        }

        key = foo
        value = object #2 (::omero::RLong)
        {
            _val = 1
        }

        key = bar
        value = object #3 (::omero::RLong)
        {
            _val = 2
        }
    }
    theFilter = <nil>
    theOptions = <nil>
}


I tested this with the Java implementation, too. It does not show this bug.

Cheers, Bernhard

Re: ParametersI buggy in Python

PostPosted: Thu Aug 05, 2010 7:02 pm
by cblackburn
Hi Bernhard,

It's not the ParametersI object that is the singleton here but the map attribute of each of the objects you have created. If you take a look at the documentation of the __init__:
Code: Select all
        Uses (and does not copy) the given dict as the named parameter
        store in this instance. Be careful if either null is passed in
        or if this instance is being used in a multi-threaded environment.

When no argument is passed in the constructor it seems to use the same dictionary object for the map. If you do this:
Code: Select all
    params2 = ParametersI(parammap={})
    params2.addLong('foobar', 3)

you will see that params2 has a different map to params and params_foo. It is advisable to explicitly pass in a map in the constructor whether that is an empty map or one containing parameters

Colin

Re: ParametersI buggy in Python

PostPosted: Fri Aug 06, 2010 9:15 am
by cblackburn
Hi again Bernhard,

after briefly looking into this I have filed a ticket: Task #2647

Thanks for bringing this to our attention.

Colin