FHIR Chat · Handling invalid page number · ibm

Stream: ibm

Topic: Handling invalid page number


view this post on Zulip Lee Surprenant (Oct 29 2019 at 16:43):

I recently added PersistenceLayer (PL) test cases for handling invalid page numbers (AbstractPagingTest.testInvalidPage0 and AbstractPagingTest.testInvalidPage4)

view this post on Zulip Lee Surprenant (Oct 29 2019 at 16:45):

https://github.com/IBM/FHIR/pull/330 updates the JDBC impl so that it doesn't throw when we get an invalid page number

view this post on Zulip Lee Surprenant (Oct 29 2019 at 16:45):

but its causing the test to fail because its expecting an exception

view this post on Zulip Lee Surprenant (Oct 29 2019 at 16:46):

what is the proper behavior for a Persistence implementation when we receive a search with an invalid page number?

view this post on Zulip Paul Bastide (Oct 29 2019 at 16:46):

what type of invalid number?

view this post on Zulip Lee Surprenant (Oct 29 2019 at 16:46):

two examples

view this post on Zulip Paul Bastide (Oct 29 2019 at 16:46):

negative, zero...
postivie?

view this post on Zulip Lee Surprenant (Oct 29 2019 at 16:47):

negative / zero is one
more than the number of pages is the other

view this post on Zulip Lee Surprenant (Oct 29 2019 at 16:47):

so lets call them 0, and 4 (the test expects 3)

view this post on Zulip Paul Bastide (Oct 29 2019 at 16:47):

more than ... empty page

view this post on Zulip Lee Surprenant (Oct 29 2019 at 16:47):

in both cases, it is a client error

view this post on Zulip Paul Bastide (Oct 29 2019 at 16:47):

less than it should throw some loose exception / outcome or return the first page

view this post on Zulip Paul Bastide (Oct 29 2019 at 16:48):

once again.... my 1000 cents

view this post on Zulip Lee Surprenant (Oct 29 2019 at 16:48):

in https://github.com/IBM/FHIR/issues/194 we define a rule-of-thumb...that PL shouldn't throw for client errors

view this post on Zulip Lee Surprenant (Oct 29 2019 at 16:49):

...but one that our impl doesn't actually follow

view this post on Zulip Lee Surprenant (Oct 29 2019 at 16:49):

so this is an interesting test for that...

view this post on Zulip Lee Surprenant (Oct 29 2019 at 16:50):

what if we have the PL return an empty result along with an OperationOutcome with a warning that the page number was invalid?

view this post on Zulip Lee Surprenant (Oct 29 2019 at 16:51):

then, for the server, the REST layer can decide what to do with that (based on the passed Prefer "return" preference or the server config)

view this post on Zulip Lee Surprenant (Oct 29 2019 at 16:51):

and for the test, we could verify that:

  1. no results came back; and
  2. the response contains the warning

view this post on Zulip Lee Surprenant (Oct 29 2019 at 16:53):

@Paul Bastide thoughts on this proposal? or you still prefer throwing in the page 0 case?

view this post on Zulip Paul Bastide (Oct 29 2019 at 16:54):

I like the idea. I think that makes sense

view this post on Zulip Paul Bastide (Oct 29 2019 at 16:54):

it's a parseable result

view this post on Zulip Lee Surprenant (Oct 29 2019 at 16:54):

@Albert(Xu) Wang @John Timm ? ^

view this post on Zulip Lee Surprenant (Oct 29 2019 at 16:55):

i also kind of like paul's idea of returning page 1 if they ask for a negative or 0 page. any objections to this?

view this post on Zulip Lee Surprenant (Oct 29 2019 at 16:56):

something totally unexpected, but potentially handy, would be to interpret negative pages as index number from the back (like negative python array indices) :-)

view this post on Zulip John Timm (Oct 29 2019 at 17:36):

I support the option of using 1 if the page number is negative or zero

view this post on Zulip Lee Surprenant (Oct 29 2019 at 17:41):

and in the case of page number > last page, we just return 0 results?

view this post on Zulip John Timm (Oct 29 2019 at 17:43):

The reason why we no longer see an exception is because pagination happens on a List of resource ids, previously, we had a problem where when the list was empty, it was generating invalid SQL and ultimately throwing a FHIRPersistenceException. Now an empty list is returned if there are no resource ids for a given page (i.e. an invalid offset).

view this post on Zulip John Timm (Oct 29 2019 at 17:44):

should we have logic like this:
if (page < min) page = min
if (page > max) page = max
?

view this post on Zulip Lee Surprenant (Oct 29 2019 at 17:47):

i like the page<min check

view this post on Zulip Lee Surprenant (Oct 29 2019 at 17:47):

i think we're in a greement there

view this post on Zulip Lee Surprenant (Oct 29 2019 at 17:48):

for page > max, I think we're better off returning empty

view this post on Zulip Lee Surprenant (Oct 29 2019 at 17:48):

but i don't feel that strongly

view this post on Zulip John Timm (Oct 29 2019 at 17:48):

That's fair

view this post on Zulip Lee Surprenant (Oct 29 2019 at 17:49):

it would enable lazy folks to just keep incrementing page number til they don't get anything

view this post on Zulip Lee Surprenant (Oct 29 2019 at 17:49):

(as opposed to checking either the total or the lastpage like they should)

view this post on Zulip John Timm (Oct 29 2019 at 17:49):

Have we decided the best place to put the logic? I can add the change to my PR. Also, we will need to tweak the unit tests accordingly.

view this post on Zulip Lee Surprenant (Oct 29 2019 at 17:49):

no, we havn't determined where yet. yes, if you can add to your PR that would be ideal

view this post on Zulip John Timm (Oct 29 2019 at 17:51):

sure, i'll dig in and figure out where to put it

view this post on Zulip John Timm (Oct 29 2019 at 17:52):

so then on the search result bundle what do we put for prev / next if page > max = no results

view this post on Zulip John Timm (Oct 29 2019 at 17:52):

will we just keep reporting imaginary pages?

view this post on Zulip John Timm (Oct 29 2019 at 17:53):

I guess it would keep things consistent

view this post on Zulip John Timm (Oct 29 2019 at 17:53):

but it seems a bit odd to have self = 5000, pref = 4999 and next = 5001 when we are already way out of range of the actually paged data

view this post on Zulip Lee Surprenant (Oct 29 2019 at 17:54):

good question. i was mostly focused on whats the proper response from the Persistence Layer's perspective

view this post on Zulip Lee Surprenant (Oct 29 2019 at 17:55):

if we want, we return success=false

view this post on Zulip Lee Surprenant (Oct 29 2019 at 17:55):

and REST layer could map the OperationOutcome to a 400 error

view this post on Zulip John Timm (Oct 29 2019 at 17:56):

I'd be tempted to do that for all invalid page numbers... negative, zero, > max, etc.

view this post on Zulip John Timm (Oct 29 2019 at 17:57):

I'm just trying to make sure things are (mostly) consistent across the board

view this post on Zulip Lee Surprenant (Oct 29 2019 at 17:57):

yeah

view this post on Zulip Lee Surprenant (Oct 29 2019 at 17:58):

does spec define behavior for invalid page numbers?

view this post on Zulip Lee Surprenant (Oct 29 2019 at 18:00):

https://www.hl7.org/fhir/http.html#paging

view this post on Zulip Lee Surprenant (Oct 29 2019 at 18:02):

doesn't really help

view this post on Zulip John Timm (Oct 29 2019 at 18:02):

there is no official _page parameter

view this post on Zulip John Timm (Oct 29 2019 at 18:02):

only _count

view this post on Zulip John Timm (Oct 29 2019 at 18:03):

and if _count=0 then it should be interpreted as _summary=count

view this post on Zulip Lee Surprenant (Oct 29 2019 at 18:04):

yeah, i guess the _page parameter was our invention

view this post on Zulip Lee Surprenant (Oct 29 2019 at 18:04):

and what matters is the links in the response

view this post on Zulip Lee Surprenant (Oct 29 2019 at 18:05):

anyway, i think the cop-out on this issue is https://github.com/IBM/FHIR/issues/254 :-)

view this post on Zulip Lee Surprenant (Oct 29 2019 at 18:06):

lenient: < 1 -> 1; > last -> last
strict: < 1 or > last -> 400 error

view this post on Zulip Lee Surprenant (Oct 29 2019 at 18:07):

we already hide prev and next links for the first/last entry. so on that front we could just exclude them both if we have an invalid page number

view this post on Zulip John Timm (Oct 29 2019 at 18:08):

we need the lenient/strict behavior for invalid count as well

view this post on Zulip John Timm (Oct 29 2019 at 18:09):

and also we need _count=0 to invoke _summary=count

view this post on Zulip Lee Surprenant (Oct 29 2019 at 18:09):

I think 254 can cover _count validation, but wanna open new related issue for handling _count=0 ?

view this post on Zulip John Timm (Oct 29 2019 at 18:11):

@Lee Surprenant
254 can cover page and new issue for count or vice versa?

view this post on Zulip Lee Surprenant (Oct 29 2019 at 19:02):

sorry, i just meant 254 can cover the "validation" (and use of handling pref) for all parameters (_count, _page, and all others)

view this post on Zulip Lee Surprenant (Oct 29 2019 at 19:03):

so open a new issue for handling _count=0


Last updated: Apr 12 2022 at 19:14 UTC