We're Hiring!

ParametersI buggy in Python

General and open developer discussion about using OMERO APIs from C++, Java, Python, Matlab and more! Please new questions at https://forum.image.sc/tags/omero
Please note:
Historical discussions about OMERO. Please look for and ask new questions at https://forum.image.sc/tags/omero

If you are having trouble with custom code, please provide a link to a public repository, ideally GitHub.

ParametersI buggy in Python

Postby bernhard » Wed Aug 04, 2010 12:02 pm

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
bernhard
 
Posts: 37
Joined: Mon Jun 22, 2009 7:18 am

Re: ParametersI buggy in Python

Postby cblackburn » Thu Aug 05, 2010 7:02 pm

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
cblackburn
 
Posts: 85
Joined: Mon May 25, 2009 9:03 pm

Re: ParametersI buggy in Python

Postby cblackburn » Fri Aug 06, 2010 9:15 am

Hi again Bernhard,

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

Thanks for bringing this to our attention.

Colin
cblackburn
 
Posts: 85
Joined: Mon May 25, 2009 9:03 pm


Return to Developer Discussion

Who is online

Users browsing this forum: No registered users and 1 guest