Skip to content

Fix rest api filtering#3526

Merged
tardyp merged 5 commits intobuildbot:masterfrom
jangmarker:fix-rest-api-filtering
Sep 5, 2017
Merged

Fix rest api filtering#3526
tardyp merged 5 commits intobuildbot:masterfrom
jangmarker:fix-rest-api-filtering

Conversation

@jangmarker
Copy link
Copy Markdown
Contributor

@jangmarker jangmarker commented Aug 15, 2017

Fixes queries like:
/api/v2/builds?builderid__eq=1&builderid__eq=2

This would have yielded an empty result with the previous code.

Contributor Checklist:

  • I have updated the unit tests
  • I have created a file in the master/buildbot/newsfragment directory (and read the README.txt in that directory)
  • I have updated the appropriate documentation
    code is fixed to match the documentation

@jangmarker jangmarker force-pushed the fix-rest-api-filtering branch from 7f437da to 45092b7 Compare August 15, 2017 14:43
@codecov
Copy link
Copy Markdown

codecov bot commented Aug 15, 2017

Codecov Report

Merging #3526 into master will increase coverage by 0.06%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3526      +/-   ##
==========================================
+ Coverage   88.29%   88.36%   +0.06%     
==========================================
  Files         323      323              
  Lines       33878    34047     +169     
==========================================
+ Hits        29912    30085     +173     
+ Misses       3966     3962       -4
Impacted Files Coverage Δ
master/buildbot/data/resultspec.py 91.2% <100%> (+0.21%) ⬆️
master/buildbot/process/builder.py 84.54% <0%> (+1.36%) ⬆️
master/buildbot/process/build.py 94.12% <0%> (+1.37%) ⬆️
master/buildbot/worker/openstack.py 97.4% <0%> (+1.45%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e1cbfd9...624ec02. Read the comment docs.

@tardyp
Copy link
Copy Markdown
Member

tardyp commented Aug 15, 2017

good catch. This needs unit tests!

does that also fix #3527 ?

@jangmarker jangmarker force-pushed the fix-rest-api-filtering branch from ae99f21 to f4d0848 Compare August 16, 2017 02:59
@jangmarker
Copy link
Copy Markdown
Contributor Author

jangmarker commented Aug 16, 2017

I've added unit tests, however, I haven't found a usage of the database contains operator - the tags property in /builders/ is not queried from the database, it seems. Maybe I've been overlooking something.

It doesn't fix #3527, in fact I discovered #3527 while working on this. For a given list property of a database object the contains operator requires all values given in the REST call to be in that list. This is a sensible query, but a query where at least one of the values given in the REST call have to be in the list property is not possible at the moment (at least I haven't found a way).

@jangmarker jangmarker force-pushed the fix-rest-api-filtering branch from f4d0848 to 23e237d Compare August 16, 2017 03:10
@tardyp
Copy link
Copy Markdown
Member

tardyp commented Aug 16, 2017

Hi @jangmarker the Rest API filtering is featured around the needs for the UI.
I think nobody actually looked at the plural case for contains.

If you have usecases, I think it makes more sense to have the contains operator have a default 'or' behaviour. It better matches the behaviour for 'eq'.
We could add a xcontains operator, which has a 'and' plural behaviour.

plural_operators_sql = {
'eq': lambda d, v: d.in_(v),
'ne': lambda d, v: d.notin_(v),
'contains': lambda d, vs: (v.in_(d) for v in vs),
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.

needs a plural test for contains. I am not sure how this code would work

@@ -49,17 +49,26 @@ class FieldBase(object):
'contains': lambda d, v: set(v) <= set(d),
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.

looks like this 'old' code should provide a OR behaviour at data API level.
It is just the sql mode which was not implemented

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Currently the old code does not provide OR behavior. For instance:

  1. https://nine.buildbot.net/api/v2/builders?tags__contains=buildbot&order=builderid
    yields multiple builders, including builderid: 1 (first one)
  2. https://nine.buildbot.net/api/v2/builders?tags__contains=try&order=builderid
    yields one builder builderid: 1
  3. https://nine.buildbot.net/api/v2/builders?tags__contains=try&tags__contains=buildbot&order=builderid (combination of 1+2)
    yields only one builder (AND behavior), but with OR it would yield all builders shown in the queries 1 and 2

I'll create a new pull request that changes the contains behavior to OR and then will adapt this request accordingly.

Copy link
Copy Markdown
Member

@tardyp tardyp left a comment

Choose a reason for hiding this comment

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

fix the contain behaviour

@tardyp
Copy link
Copy Markdown
Member

tardyp commented Aug 21, 2017

@jangmarker I think you wanted to rebase this PR?

@jangmarker jangmarker force-pushed the fix-rest-api-filtering branch from 23e237d to e26cf36 Compare August 23, 2017 02:00
@jangmarker
Copy link
Copy Markdown
Contributor Author

Yes, sorry, I didn't make it before vacation. My response times will be rather slow until September.

Fixes queries like:
/api/v2/builds?builderid__eq=1&builderid__eq=2

This would have yielded an empty result with the previous code.
@jangmarker jangmarker force-pushed the fix-rest-api-filtering branch from e26cf36 to 313c3d1 Compare September 4, 2017 03:51
@jangmarker jangmarker force-pushed the fix-rest-api-filtering branch from 313c3d1 to 624ec02 Compare September 4, 2017 03:52
@tardyp tardyp merged commit d4218cc into buildbot:master Sep 5, 2017
@jangmarker jangmarker deleted the fix-rest-api-filtering branch September 7, 2017 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants