Skip to content

Improve mapped column handling for REST pagination and NextLink creation fixes#1319

Merged
seantleonard merged 24 commits intomainfrom
dev/seleonar/issue1315_restpagination_keynotfound
Mar 23, 2023
Merged

Improve mapped column handling for REST pagination and NextLink creation fixes#1319
seantleonard merged 24 commits intomainfrom
dev/seleonar/issue1315_restpagination_keynotfound

Conversation

@seantleonard
Copy link
Contributor

@seantleonard seantleonard commented Mar 9, 2023

Why make this change?

What is this change?

  • changes TryResolveJsonElementToScalarVariable(element.GetProperty(column)
    • to: TryResolveJsonElementToScalarVariable(element.GetProperty(exposedColumnName)

Issue when loading request "FindMany" within pagination token

With a request like GET https://localhost:5001/api/todo
This result is returned as next link:

"nextLink": "https://localhost:5001/api/todo?System.Collections.Specialized.NameValueCollection"

How was this tested?

  • Integration Tests- updated existing integration tests.
  • Unit Tests

Sample Request(s)

  • Using the configuration/SQL db script provided in the issue, the following request will succeed now and provide a valid NextLink: https://localhost:5001/api/todo?$orderby=title desc, tid asc

…he returned db result. Should be mapped value not unmapped value. Then addressed uncovered encoding differences in tests vs engine and made consistent. i.e. `%3d` vs correctly upper case `%3D`
Copy link
Contributor

@aaronburtle aaronburtle left a comment

Choose a reason for hiding this comment

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

Nice find, thanks for fixing!

Copy link
Contributor

@abhishekkumams abhishekkumams left a comment

Choose a reason for hiding this comment

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

Interesting Find.

Copy link
Collaborator

@Aniruddh25 Aniruddh25 left a comment

Choose a reason for hiding this comment

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

Thanks for fixing so quickly, waiting for addition of tests

…ected behavior of correct nextlink generation.
…tity to all setup scripts for all db flavors and update reference configuration files.
…r used in the nextLink pagination cursor. Tests added for all db flavors, sql config references updated with new entities that are used in tests, and commands in config generation scripts are updated.
…ms and is also not the first. Which checks for alternative prefix to after query param: &$ and not ?$
Copy link
Collaborator

@Aniruddh25 Aniruddh25 left a comment

Choose a reason for hiding this comment

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

LGTM, after simplifying the config files!

…rators as they are no present in the test project.
… dev/seleonar/issue1315_restpagination_keynotfound
…and mappedbookmarks table because generate_series is only compatible with sql2022 and not sql2019/localdb
@seantleonard seantleonard merged commit 09648ee into main Mar 23, 2023
@seantleonard seantleonard deleted the dev/seleonar/issue1315_restpagination_keynotfound branch March 23, 2023 23:45
Aniruddh25 pushed a commit that referenced this pull request Mar 24, 2023
…ion fixes (#1319)

## Why make this change?

- Closes #1315 which highlights an issue with pagination logic not
resolving column names from database results using "mapped" column
names, when configured. Instead, the current column resolution always
uses "backing" column names.

## What is this change?
- changes
`TryResolveJsonElementToScalarVariable(element.GetProperty(column)`
- to:
`TryResolveJsonElementToScalarVariable(element.GetProperty(exposedColumnName)`

### Issue when loading request "FindMany" within pagination token
With a request like ` GET https://localhost:5001/api/todo`
This result is returned as next link:
```json
"nextLink": "https://localhost:5001/api/todo?System.Collections.Specialized.NameValueCollection"
```
- Fixing the column resolution uncovered this bug with how **initial**
pagination next links are generated. (not a problem when a pagination
link is included with request). The `NameValueCollection` which contains
all query string key/value pairs was not being resolved into a query
string and the nextLink looked like:
`"nextLink":
"https://localhost:5001/api/todo/System.Collections.Specialized.NameValueCollection"`
- The fix was to add explicit iteration of the key value pairs in the
collection and generate a well-formed Query String using AspNetCore
helper utilities.
- This uncovered a subtle difference in how the engine and test fixture
escape query string payload for URLs. Tests were using a helper which
incorrectly escaped invalid URI characters with lower case hex value.
i.e. `%3d`. Then proper form would be uppercase -> `%3D`
    - Discussion https://stackoverflow.com/a/48301702/18174950
    - https://stackoverflow.com/a/47877559/18174950
-
https://edi.wang/post/2018/11/25/netcore-webutility-urlencode-httputility-urlencode
    - https://stackoverflow.com/a/51829522/18174950

## How was this tested?

- [x] Integration Tests- updated existing integration tests.
- [ ] Unit Tests

## Sample Request(s)

- Using the configuration/SQL db script provided in the issue, the
following request will succeed now and provide a valid NextLink:
`https://localhost:5001/api/todo?$orderby=title desc, tid asc`
Aniruddh25 pushed a commit that referenced this pull request Mar 24, 2023
…ion fixes (#1319)

- Closes #1315 which highlights an issue with pagination logic not
resolving column names from database results using "mapped" column
names, when configured. Instead, the current column resolution always
uses "backing" column names.

- changes
`TryResolveJsonElementToScalarVariable(element.GetProperty(column)`
- to:
`TryResolveJsonElementToScalarVariable(element.GetProperty(exposedColumnName)`

With a request like ` GET https://localhost:5001/api/todo`
This result is returned as next link:
```json
"nextLink": "https://localhost:5001/api/todo?System.Collections.Specialized.NameValueCollection"
```
- Fixing the column resolution uncovered this bug with how **initial**
pagination next links are generated. (not a problem when a pagination
link is included with request). The `NameValueCollection` which contains
all query string key/value pairs was not being resolved into a query
string and the nextLink looked like:
`"nextLink":
"https://localhost:5001/api/todo/System.Collections.Specialized.NameValueCollection"`
- The fix was to add explicit iteration of the key value pairs in the
collection and generate a well-formed Query String using AspNetCore
helper utilities.
- This uncovered a subtle difference in how the engine and test fixture
escape query string payload for URLs. Tests were using a helper which
incorrectly escaped invalid URI characters with lower case hex value.
i.e. `%3d`. Then proper form would be uppercase -> `%3D`
    - Discussion https://stackoverflow.com/a/48301702/18174950
    - https://stackoverflow.com/a/47877559/18174950
-
https://edi.wang/post/2018/11/25/netcore-webutility-urlencode-httputility-urlencode
    - https://stackoverflow.com/a/51829522/18174950

- [x] Integration Tests- updated existing integration tests.
- [ ] Unit Tests

- Using the configuration/SQL db script provided in the issue, the
following request will succeed now and provide a valid NextLink:
`https://localhost:5001/api/todo?$orderby=title desc, tid asc`
Aniruddh25 added a commit that referenced this pull request Mar 24, 2023
## Why make this change?

Cherry picking the following changes to create a patch for 0.5.x:
- #1349 
- #1319 
- #1351

---------

Co-authored-by: Jun Su <70380073+junsu0ms@users.noreply.github.com>
Co-authored-by: Sean Leonard <sean.leonard@microsoft.com>
Co-authored-by: abhishekkumams <102276754+abhishekkumams@users.noreply.github.com>
abhishekkumams pushed a commit that referenced this pull request Mar 30, 2023
…ion fixes (#1319)

## Why make this change?

- Closes #1315 which highlights an issue with pagination logic not
resolving column names from database results using "mapped" column
names, when configured. Instead, the current column resolution always
uses "backing" column names.

## What is this change?
- changes
`TryResolveJsonElementToScalarVariable(element.GetProperty(column)`
- to:
`TryResolveJsonElementToScalarVariable(element.GetProperty(exposedColumnName)`


### Issue when loading request "FindMany" within pagination token 
With a request like ` GET https://localhost:5001/api/todo`
This result is returned as next link: 
```json
"nextLink": "https://localhost:5001/api/todo?System.Collections.Specialized.NameValueCollection"
```
- Fixing the column resolution uncovered this bug with how **initial**
pagination next links are generated. (not a problem when a pagination
link is included with request). The `NameValueCollection` which contains
all query string key/value pairs was not being resolved into a query
string and the nextLink looked like:
`"nextLink":
"https://localhost:5001/api/todo/System.Collections.Specialized.NameValueCollection"`
- The fix was to add explicit iteration of the key value pairs in the
collection and generate a well-formed Query String using AspNetCore
helper utilities.
- This uncovered a subtle difference in how the engine and test fixture
escape query string payload for URLs. Tests were using a helper which
incorrectly escaped invalid URI characters with lower case hex value.
i.e. `%3d`. Then proper form would be uppercase -> `%3D`
    - Discussion https://stackoverflow.com/a/48301702/18174950
    - https://stackoverflow.com/a/47877559/18174950
-
https://edi.wang/post/2018/11/25/netcore-webutility-urlencode-httputility-urlencode
    - https://stackoverflow.com/a/51829522/18174950

## How was this tested?

- [x] Integration Tests- updated existing integration tests. 
- [ ] Unit Tests

## Sample Request(s)

- Using the configuration/SQL db script provided in the issue, the
following request will succeed now and provide a valid NextLink:
`https://localhost:5001/api/todo?$orderby=title desc, tid asc`
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.

[Bug]: Error "The given key was not present in the dictionary." returned when using mapping and pagination

6 participants