Repository navigation
Answer 400 for a non-integer limit on @users - #2046
kunalKumar-13 wants to merge 5 commits into
Conversation
|
@kunalKumar-13 thanks for creating this Pull Request and helping to improve Plone! TL;DR: Finish pushing changes, pass all other checks, then paste a comment: To ensure that these changes do not break other parts of Plone, the Plone test suite matrix needs to pass, but it takes 30-60 min. Other CI checks are usually much faster and the Plone Jenkins resources are limited, so when done pushing changes and all other checks pass either start all Jenkins PR jobs yourself, or simply add the comment above in this PR to start all the jobs automatically. Happy hacking! |
|
@jenkins-plone-org please run jobs |
@users parsed its limit with a bare int(), so a value that is not an
integer raised ValueError and the request became a 500:
GET /@users?query=noam&limit=abc -> 500
GET /@users?query=noam&limit=1.5 -> 500
Every other service parses integer parameters with parse_int, which
answers 400 with "Invalid <name>: Not an integer" -- including
querystring-search, which reads a limit of its own. This is the one place
that did not.
parse_qs hands back a list per key, so the value is unwrapped before
parse_int sees it.
Values that already worked are unchanged: limit=1, an empty limit and a
negative limit all still return 200.
96be034 to
8c12270
Compare
|
Rebased onto current @jenkins-plone-org please run jobs |
|
Jenkins has reported since the rebase, and two of the six jobs are red. They are not from this change — the acceptance layer is timing out on browser startup. In the That is
It is not specific to this PR, or to me. Across the currently open pull requests here:
Same pattern on the other three I nudged today — One thing I should own: these four jobs had been sitting Nothing to do on this PR as far as I can tell. Happy to re-trigger if a fresh run would help. |
|
The two red Jenkins jobs are not this PR, and — unlike the browser-install problem I #147 has three robot in |
|
@jenkins-plone-org please run jobs |
What
@usersparses itslimitwith a bareint(), so a value that is not an integer raisesValueErrorand the request becomes a 500.Run against a real Plone with the project's own test layer:
Why this is the odd one out
plone.restapialready has the right helper for this, and every other service uses it:batching.py(b_start,b_size),navigation/get.py(expand.navigation.depth),discussion/conversation.py(comment_id) andquerystringsearch/get.pyall go through it — andquerystringsearchreads alimitof its own that way:So the same bad value is a 400 on
@querystring-searchand a 500 on@users. This makes@usersbehave like the rest.The change
services/users/get.pynow routeslimitthroughparse_int.parse_qsreturns a list per key, so the value is unwrapped beforeparse_intsees it — that is the only wrinkle, and there is a comment saying so.Nothing else moves.
limit=1, an emptylimit, a missinglimitand a negativelimitall behave exactly as before.Tests
Written first and run before the fix, where they failed with
AssertionError: 400 != 500for each ofabc,1.5and10,20.test_list_users_with_non_integer_limit— asserts 400 and that the message names the parametertest_list_users_with_valid_limit— pins1, `` and-1at 200, so a later change cannot quietly turn a working value into an errorzope-testrunner -m plone.restapi.tests.test_services_users— 95 tests, 0 failures, 0 errors.The repository's own pre-commit hooks pass on commit: pyupgrade, isort, black, flake8, codespell, pyroma, check-python-versions.