Skip to content

Conversation

@enjoy-binbin
Copy link
Contributor

@enjoy-binbin enjoy-binbin commented Jul 23, 2021

With an empty src key, we need to deal with two situations:

  1. non-STORE: We should return emptyarray.
  2. STORE: Try to delete the store key and return 0.

This applies to both GEOSEARCHSTORE (new to v6.2), and
also GEORADIUS STORE (which was broken since forever)

This pr try to fix #9261. i.e. both STORE variants would have behaved like the non-STORE variants when the source key was missing, returning an empty array and not deleting the destination key, instead of returning 0, and deleting the destination key.

Also add more tests for some commands.

  • GEORADIUS: wrong type src key、non existing src key、empty search、store with non existing src key、store with empty search
  • GEORADIUSBYMEMBER: wrong type src key、non existing src key、non existing member、store with non existing src key
  • GEOSEARCH: wrong type src key、non existing src key、empty search、frommember with non existing member
  • GEOSEARCHSTORE: wrong type key、non existing src key、fromlonlat with empty search、frommember with non existing member

With an empty src key, we need to deal with two situations:
1. non-store: We should return emptyarray.
2. store: Try to delete the store key and return 0.
@oranagra oranagra added release-notes indication that this issue needs to be mentioned in the release notes breaking-change This change can potentially break existing application labels Jul 25, 2021
@oranagra
Copy link
Member

Thanks.
p.s. this follows the footsteps of #9089, so i suppose no core-team major-decision is needed.

Copy link
Member

@oranagra oranagra left a comment

Choose a reason for hiding this comment

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

please add tests for all these cases (both missing key and one with no results found), for all variants...

@oranagra
Copy link
Member

@redis/core-team this is very similar to the case of #9089, with one exception: the bugs in GEORADIUS were present in the original version (before v6.2), not added by the refactoring for GEOSEARCH.
please approve fixing these for both commands.

@oranagra oranagra changed the title Geo-store with empty src key should not return emptyarray. GEO* STORE with empty src key delete the dest key and return 0, not empty array Jul 25, 2021
@oranagra oranagra added the state:major-decision Requires core team consensus label Jul 25, 2021
enjoy-binbin and others added 4 commits July 25, 2021 14:40
Co-authored-by: Oran Agra <oran@redislabs.com>
Co-authored-by: Oran Agra <oran@redislabs.com>
yossigo
yossigo previously approved these changes Jul 25, 2021
Copy link
Member

@oranagra oranagra left a comment

Choose a reason for hiding this comment

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

LGTM..
please add tests for both cases (store and non-store), of all of these various cases and commands (including missing key and empty-search).
thanks!

@oranagra oranagra added state:to-be-merged The PR should be merged soon, even if not yet ready, this is used so that it won't be forgotten approval-needed Waiting for core team approval to be merged labels Jul 25, 2021
@itamarhaber
Copy link
Member

Approving both fixes.

@enjoy-binbin
Copy link
Contributor Author

@oranagra Please check my last two commits.
I seem to have added a lot of tests that I think are missing or need to be covered...
Maybe it's redundant, but I want to cover as much as I can (It's not completely covered)
Let me know if i am missing somethings

Copy link
Member

@oranagra oranagra left a comment

Choose a reason for hiding this comment

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

@enjoy-binbin it is a bit hard to write / read / maintain such a big pile of tests, i think we can refactor that to be much easier.

it is clear that we have a bunch of district tests for

  • missing key
  • wrong type key
  • empty results
  • etc

and we have the STORE and non-STORE variants to test on each of these.

we also have both the old (GEORADIUS) and new (GEOSEARCH) forms to test on each of these.

but first the above combinations (GEORADIUS vs GEOSEARCH) always expect the same, so one test can call both types of commands and match them to the same expected response, secondly maybe there's a better way to share code even between the STORE and non-STORE variants.

e.g. imagine this pseudo code:

proc verify_geo_edge_response {expected_response expected_store_response} {
    assert_match $expected_response [r GEORADIUS ...]
    assert_match $expected_response [r GEOSEARCH ...]
    assert_match $expected_store_response [r GEORADIUS ... STORE]
    # putting STORE arg first
    assert_match $expected_store_response [r GEORADIUS STORE ...]
    assert_match $expected_store_response [r GEOSEARCHSTORE ...]

# same can probably be done for BYLATLON and BYMEMBER
}

test {geo missing key} {
    del src{t}
    verify_geo_edge_response {} 0
}

test {geo wrong type} {
    set src{t} asdf
    verify_geo_edge_response "ERR*" "ERR*"
}

# and so on...

have a look at your various tests, i hope that all of them can fit into that pattern in some way, and if you find any that aren't we can still add dedicated tests for them.

@enjoy-binbin enjoy-binbin requested a review from oranagra July 27, 2021 03:26
Copy link
Member

@oranagra oranagra left a comment

Choose a reason for hiding this comment

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

the last commit certainly shaved a lot of test lines and even though the new code is a bit more complicated to read, it still makes it much easier to see what's being done and what may be missing.

i didn't go though all the deleted code myself. do the last version indeed cover everything the old one did (except the withcoord / asc options etc that are not needed for our issue)?

@oranagra oranagra merged commit 86555ae into redis:unstable Aug 1, 2021
@enjoy-binbin enjoy-binbin deleted the issue_9261 branch August 1, 2021 16:37
JackieXie168 pushed a commit to JackieXie168/redis that referenced this pull request Sep 8, 2021
…mpty array (redis#9271)

With an empty src key, we need to deal with two situations:
1. non-STORE: We should return emptyarray.
2. STORE: Try to delete the store key and return 0.

This applies to both GEOSEARCHSTORE (new to v6.2), and
also GEORADIUS STORE (which was broken since forever)

This pr try to fix redis#9261. i.e. both STORE variants would have behaved
like the non-STORE variants when the source key was missing,
returning an empty array and not deleting the destination key,
instead of returning 0, and deleting the destination key.

Also add more tests for some commands.
- GEORADIUS: wrong type src key, non existing src key, empty search,
  store with non existing src key, store with empty search
- GEORADIUSBYMEMBER: wrong type src key, non existing src key,
  non existing member, store with non existing src key
- GEOSEARCH: wrong type src key, non existing src key, empty search,
  frommember with non existing member
- GEOSEARCHSTORE: wrong type key, non existing src key,
  fromlonlat with empty search, frommember with non existing member

Co-authored-by: Oran Agra <oran@redislabs.com>
@oranagra oranagra mentioned this pull request Oct 4, 2021
oranagra added a commit that referenced this pull request Oct 4, 2021
…mpty array (#9271)

With an empty src key, we need to deal with two situations:
1. non-STORE: We should return emptyarray.
2. STORE: Try to delete the store key and return 0.

This applies to both GEOSEARCHSTORE (new to v6.2), and
also GEORADIUS STORE (which was broken since forever)

This pr try to fix #9261. i.e. both STORE variants would have behaved
like the non-STORE variants when the source key was missing,
returning an empty array and not deleting the destination key,
instead of returning 0, and deleting the destination key.

Also add more tests for some commands.
- GEORADIUS: wrong type src key, non existing src key, empty search,
  store with non existing src key, store with empty search
- GEORADIUSBYMEMBER: wrong type src key, non existing src key,
  non existing member, store with non existing src key
- GEOSEARCH: wrong type src key, non existing src key, empty search,
  frommember with non existing member
- GEOSEARCHSTORE: wrong type key, non existing src key,
  fromlonlat with empty search, frommember with non existing member

Co-authored-by: Oran Agra <oran@redislabs.com>
(cherry picked from commit 86555ae)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approval-needed Waiting for core team approval to be merged breaking-change This change can potentially break existing application release-notes indication that this issue needs to be mentioned in the release notes state:major-decision Requires core team consensus state:to-be-merged The PR should be merged soon, even if not yet ready, this is used so that it won't be forgotten

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

[BUG] GEOSEARCHSTORE returns an empty array when src points to an empty key

4 participants