Skip to content

Blitz buildQuery params#4950

Merged
jburel merged 19 commits into
ome:developfrom
will-moore:blitz_buildQuery_params
Dec 15, 2016
Merged

Blitz buildQuery params#4950
jburel merged 19 commits into
ome:developfrom
will-moore:blitz_buildQuery_params

Conversation

@will-moore
Copy link
Copy Markdown
Member

@will-moore will-moore commented Nov 17, 2016

What this PR does

This is a subset of #4945 containing just the BlitzGateway and test changes.

This moves more logic for building queries to the BlitzGateway, to reduce duplication within api_query.py.

This means that the _getQueryString() for each BlitzGateway Wrapper object now returns a base query string, params and clauses. These are then augmented in conn.buildQuery(), which is used both by conn.getObjects() (and by the web /api_query.py - see #4945).

The params argument in
conn.getObjects("Project", params)
can now be an omero.sys.Parameters object (as before) OR can be a dictionary of parameters to support additional filtering.
E.g. {'page': 1, 'limit': 100, 'order_by': 'name', 'owner': 1, 'project': 5}

cc @chris-allan

@will-moore will-moore changed the title Blitz build query params Blitz buildQuery params Nov 17, 2016
@jburel jburel added the develop label Nov 18, 2016
@will-moore
Copy link
Copy Markdown
Member Author

@chris-allan If you could have a look at this when you get time, that would be great, thanks. And #4930 too (lower priority). Cheers.

return obj.getValue()

def _getQueryString(self):
def _getQueryString(self, opts=None):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is going to be used more extensively now and its return value has changed to a tuple the function needs pretty thorough documentation and we should definitely mark it for detailed review in the changelog. We have many examples where this method is overridden and/or its return value is used.

opts = None
inputParams = None

if isinstance(params, dict):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm really not sure about this. At a minimum it needs documentation and to detailed review in the changelog as above. While it certainly keeps the prototype is it not feasible to add opts as an additional keyword argument?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood. I wasn't sure about this either. I was just trying to avoid too many arguments, thinking that use of params would mostly be covered by opts instead (they cover mostly the same functionality). But it can get confusing in the implementation.
I'm happy to add opts as additional argument. Then there's the question of whether params or opts takes precedence (E.g. if you specify different pagination or owner in each)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding opts as a keyword argument is certainly preferable from my perspective. @aleksandra-tarkowska would probably like the opportunity to comment.

I think you can choose one and document it as taking precedence. Whichever one is the subset of the other is probably the a good candidate but I can see arguments both ways. That is, if you have the possibility to configure 50 things with opts and have params only able to configure 10 the settings from params should probably override those set in params if a call were made where both were present.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where is the unit test?

"join fetch obj.details.group "
"join fetch obj.details.creationEvent")
query = ("select obj from Annotation obj "
"join fetch obj.details.owner as owner "
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is loosing the details.group fetch here not a regression?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See ce55154 in original PR #4945 for when and why details.group was removed from these queries. cc @joshmoore

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, no problem. Just something we should document and probably schedule time to fix at a fundamental level. During work with omero-es I haven't noticed issues like this and I'm definitely loading multiple groups that are not the default group. So I guess it's a combination of factors?

/cc @aleksandra-tarkowska

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you add unit test as well

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aleksandra-tarkowska Unit tests for every _getQueryString() would be a lot to add to this PR, but maybe just for the ones that handle opts parameter.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why? we need one at least for parent. You could parametrize the test. In my opinion well written test is much better then the doc

"join fetch obj.details.group "
"join fetch obj.details.creationEvent join fetch obj.file")
query = ("select obj from FileAnnotation obj "
"join fetch obj.details.owner as owner "
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above. Is loosing the details.group fetch here not a regression?

"join fetch obj.details.group "
"join fetch obj.details.creationEvent")
query = ("select obj from TimestampAnnotation obj "
"join fetch obj.details.owner as owner "
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above. Is loosing the details.group fetch here not a regression?

"join fetch obj.details.group "
"join fetch obj.details.creationEvent")
query = ("select obj from TagAnnotation obj "
"join fetch obj.details.owner as owner "
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above. Is loosing the details.group fetch here not a regression?

"join fetch obj.details.group "
"join fetch obj.details.creationEvent")
query = ("select obj from CommentAnnotation obj "
"join fetch obj.details.owner as owner "
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above. Is loosing the details.group fetch here not a regression?

"join fetch obj.details.group "
"join fetch obj.details.creationEvent")
query = ("select obj from LongAnnotation obj "
"join fetch obj.details.owner as owner "
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above. Is loosing the details.group fetch here not a regression?

"join fetch obj.details.group "
"join fetch obj.details.creationEvent")
query = ("select obj from DoubleAnnotation obj "
"join fetch obj.details.owner as owner "
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above. Is loosing the details.group fetch here not a regression?

"join fetch obj.details.group "
"join fetch obj.details.creationEvent")
query = ("select obj from TermAnnotation obj "
"join fetch obj.details.owner as owner "
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above. Is loosing the details.group fetch here not a regression?

@chris-allan
Copy link
Copy Markdown
Member

Just as a bit of general feedback, having a large number of flake8 fixes embedded in the commits with code changes makes review incredibly time consuming. Every changed line has to be essentially checked on a character by character basis.

Parenthetically, and I'm all for keeping a consistent and readable style, if flake8 is throwing up an error and telling us to replace this:

        return (type(a) == type(self)
                and self._obj.id == a._obj.id
                and self.getName() == a.getName())

with this:

        return (type(a) == type(self) and
                self._obj.id == a._obj.id and
                self.getName() == a.getName())

... that's taking the pedantic style application way too far in my opinion and is going to create a lot of needless and conflict inducing churn in our repositories.

/cc @sbesson, @joshmoore

@will-moore
Copy link
Copy Markdown
Member Author

@chris-allan Yes, I had to add a lot of flake8 fixes because of travis failures in #4945, see https://travis-ci.org/openmicroscopy/openmicroscopy/jobs/176394210.
Without them the PR wouldn't even be mergeable, although I guess I could port them all to another PR, merge that, then merge develop back into this PR?!

@will-moore
Copy link
Copy Markdown
Member Author

Error found by @aleksandra-tarkowska at ome/omero-gallery#11

File "/home/hudson/virtualenv/lib/python2.7/site-packages/omero_gallery/views.py", line 125, in show_group
   for d in conn.listOrphans("Dataset", eid=user_id):
 File "/opt/hudson/workspace/WEB-DEV-merge-deploy/OMERO.py/lib/python/omero/gateway/__init__.py", line 2599, in listOrphans
   query = wrapper()._getQueryString()
TypeError: _getQueryString() takes exactly 2 arguments (1 given)

@chris-allan
Copy link
Copy Markdown
Member

chris-allan commented Dec 1, 2016

Regarding the flake8 fixes even just having those fixes themselves in a separate commit would have made it a lot easier. The reviewer can then work on a commit by commit basis after those changes have been applied and it's then much easier to see what has been changed.

Was this code completely devoid of flake8 checking previously and thus we have all these changes to do or is it simply that one or more flake8 version increments have made certain stylistic or structural constructs more rigid?

Edit: Yep, regarding the differences in _getQueryString() method prototype we're "breaking" a largely internal API but one we use pretty liberally at least in our own software. We're going to have to document this quite thoroughly as mentioned above.

@jburel
Copy link
Copy Markdown
Member

jburel commented Dec 1, 2016

@will-moore: wrt flake8 better to have a separate PR that we can merge quickly
and then move forward with this PR

@will-moore will-moore reopened this Dec 5, 2016
@will-moore will-moore force-pushed the blitz_buildQuery_params branch from 17ef783 to 1353f00 Compare December 5, 2016 15:40
@will-moore will-moore closed this Dec 6, 2016
@will-moore will-moore reopened this Dec 6, 2016
@will-moore
Copy link
Copy Markdown
Member Author

@chris-allan:

@chris-allan
Copy link
Copy Markdown
Member

Thanks, @will-moore. I think the only thing I'd like to see added to the documentation are to explicitly define the supported set of opts keys for each method. Those need to be declared somewhere. You could alternatively switch to an object to define those which would make it somewhat more explicit and self documenting but that's really up to you. I'm fine with either technical approach.

@will-moore will-moore closed this Dec 7, 2016
@will-moore will-moore reopened this Dec 7, 2016
@will-moore
Copy link
Copy Markdown
Member Author

@aleksandra-tarkowska I thought about that, but I don't think I really need a series of parameters for opts and params.


@classmethod
@pytest.fixture(autouse=True)
def setup_class(cls, tmpdir, monkeypatch):
Copy link
Copy Markdown
Member

@atarkowska atarkowska Dec 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't you mean setup_method? setup_class and autouse doesn't sound right to me

ice_config = tmpdir / "ice.config"
ice_config.write("omero.host=localhost\nomero.port=4064")
monkeypatch.setenv("ICE_CONFIG", ice_config)
cls.g = _BlitzGateway()
Copy link
Copy Markdown
Member

@atarkowska atarkowska Dec 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't you teardown that object

Copy link
Copy Markdown
Member

@atarkowska atarkowska left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why actually buildQuery is not a static method?

@will-moore
Copy link
Copy Markdown
Member Author

I've looked at turning def _getQueryString() into a classmethod but this seems to need quite a lot of changes.
Since the base BlitzObjectWrapper._getQueryString() uses the OMERO_CLASS from each subclass, this fails because the OMERO_CLASS is currently only set in the def __bstrap__(self): method of each subclass, which is called when the class is instantiated.
So, while I agree that buildQuery and _getQueryString should be static / class methods, I think that this cleanup should be done in a separate PR, since it's not directly related to the change in functionality of this PR (and will confuse the changes in this PR with unrelated fixes).

I'll place my current work on this into a separate branch to create a new PR later.

@will-moore
Copy link
Copy Markdown
Member Author

If everyone is happy with this, it would be nice to get it merged so I can cleanup the other PRs that depend on it: #4945 and #4993.
Thanks.
cc @jburel

@will-moore
Copy link
Copy Markdown
Member Author

#4993 is ready to review, but I really need to get this PR merged first to clean up the changes.
Thanks.

@jburel
Copy link
Copy Markdown
Member

jburel commented Dec 13, 2016

To check tomorrow if ome/omero-gallery#11 is working before merging

@jburel
Copy link
Copy Markdown
Member

jburel commented Dec 15, 2016

"gallery" is back up on cowfish
https://cowfish.openmicroscopy.org/webtrial/gallery/show_group/0/
Merging this PR

@jburel jburel merged commit af72751 into ome:develop Dec 15, 2016
@jburel jburel added this to the 5.3.0 milestone Mar 29, 2017
@will-moore will-moore deleted the blitz_buildQuery_params branch February 18, 2019 04:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants