Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filters doesn't return any data when using numbers. #13371

Closed
3 tasks done
fimbres opened this issue May 13, 2024 · 17 comments
Closed
3 tasks done

Filters doesn't return any data when using numbers. #13371

fimbres opened this issue May 13, 2024 · 17 comments
Assignees
Labels
GraphQL Related to GraphQL API issues not-reproducible Not able to reproduce the issue question General question

Comments

@fimbres
Copy link

fimbres commented May 13, 2024

Before opening, please confirm:

JavaScript Framework

React Native

Amplify APIs

GraphQL API

Amplify Version

v6

Amplify Categories

api

Backend

Amplify CLI

Environment information

System:
    OS: macOS 14.4.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 1.60 GB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.17.1 - ~/.nvm/versions/node/v18.17.1/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 9.6.7 - ~/.nvm/versions/node/v18.17.1/bin/npm
    pnpm: 8.7.0 - /opt/homebrew/bin/pnpm
    bun: 1.0.23 - ~/.bun/bin/bun
  Browsers:
    Chrome: 124.0.6367.201
    Safari: 17.4.1
  npmPackages:
    @aws-amplify/react-native: ^1.0.28 => 1.0.28 
    @babel/core: ^7.20.0 => 7.24.4 
    @expo/vector-icons: ^14.0.0 => 14.0.0 
    @hookform/resolvers: ^3.3.4 => 3.3.4 
    @hookform/resolvers/ajv:  1.0.0 
    @hookform/resolvers/arktype:  1.0.0 
    @hookform/resolvers/class-validator:  1.0.0 
    @hookform/resolvers/computed-types:  1.0.0 
    @hookform/resolvers/io-ts:  1.0.0 
    @hookform/resolvers/joi:  1.0.0 
    @hookform/resolvers/nope:  1.0.0 
    @hookform/resolvers/superstruct:  1.0.0 
    @hookform/resolvers/typanion:  1.0.0 
    @hookform/resolvers/typebox:  1.0.0 
    @hookform/resolvers/valibot:  1.0.0 
    @hookform/resolvers/vest:  1.0.0 
    @hookform/resolvers/yup:  1.0.0 
    @hookform/resolvers/zod:  1.0.0 
    @react-native-async-storage/async-storage: 1.21.0 => 1.21.0 
    @react-native-community/datetimepicker: 7.6.1 => 7.6.1 
    @react-native-community/netinfo: 11.1.0 => 11.1.0 
    @react-native-picker/picker: 2.6.1 => 2.6.1 
    @react-navigation/native: ^6.0.2 => 6.1.17 
    @types/numeral: ^2.0.5 => 2.0.5 
    @types/react: ~18.2.45 => 18.2.79 
    HelloWorld:  0.0.1 
    aws-amplify: ^6.0.30 => 6.0.30 
    aws-amplify/adapter-core:  undefined ()
    aws-amplify/analytics:  undefined ()
    aws-amplify/analytics/kinesis:  undefined ()
    aws-amplify/analytics/kinesis-firehose:  undefined ()
    aws-amplify/analytics/personalize:  undefined ()
    aws-amplify/analytics/pinpoint:  undefined ()
    aws-amplify/api:  undefined ()
    aws-amplify/api/server:  undefined ()
    aws-amplify/auth:  undefined ()
    aws-amplify/auth/cognito:  undefined ()
    aws-amplify/auth/cognito/server:  undefined ()
    aws-amplify/auth/enable-oauth-listener:  undefined ()
    aws-amplify/auth/server:  undefined ()
    aws-amplify/data:  undefined ()
    aws-amplify/data/server:  undefined ()
    aws-amplify/datastore:  undefined ()
    aws-amplify/in-app-messaging:  undefined ()
    aws-amplify/in-app-messaging/pinpoint:  undefined ()
    aws-amplify/push-notifications:  undefined ()
    aws-amplify/push-notifications/pinpoint:  undefined ()
    aws-amplify/storage:  undefined ()
    aws-amplify/storage/s3:  undefined ()
    aws-amplify/storage/s3/server:  undefined ()
    aws-amplify/storage/server:  undefined ()
    aws-amplify/utils:  undefined ()
    expo: ~50.0.14 => 50.0.17 
    expo-dev-client: ~3.3.11 => 3.3.11 
    expo-font: ~11.10.3 => 11.10.3 
    expo-image: ~1.10.6 => 1.10.6 
    expo-image-picker: ~14.7.1 => 14.7.1 
    expo-linear-gradient: ~12.7.2 => 12.7.2 
    expo-linking: ~6.2.2 => 6.2.2 
    expo-location: ~16.5.5 => 16.5.5 
    expo-router: ~3.4.8 => 3.4.8 
    expo-splash-screen: ~0.26.4 => 0.26.4 
    expo-status-bar: ~1.11.1 => 1.11.1 
    expo-system-ui: ~2.9.3 => 2.9.4 
    expo-web-browser: ~12.8.2 => 12.8.2 
    lucide-react-native: ^0.372.0 => 0.372.0 
    moment: ^2.30.1 => 2.30.1 
    numeral: ^2.0.6 => 2.0.6 
    react: 18.2.0 => 18.2.0 
    react-dom: 18.2.0 => 18.2.0 
    react-hook-form: ^7.51.3 => 7.51.3 
    react-native: 0.73.6 => 0.73.6 
    react-native-gesture-handler: ~2.14.1 => 2.14.1 
    react-native-get-random-values: ~1.8.0 => 1.8.0 
    react-native-google-places-autocomplete: ^2.5.6 => 2.5.6 
    react-native-mask-input: ^1.2.3 => 1.2.3 
    react-native-otp-entry: ^1.6.1 => 1.6.1 
    react-native-reanimated: ~3.6.2 => 3.6.3 
    react-native-reanimated-carousel: ^3.5.1 => 3.5.1 
    react-native-safe-area-context: 4.8.2 => 4.8.2 
    react-native-screens: ~3.29.0 => 3.29.0 
    react-native-svg: 14.1.0 => 14.1.0 
    react-native-svg-transformer: ^1.3.0 => 1.3.0 
    react-native-web: ~0.19.6 => 0.19.10 
    react-native-woodpicker: ^0.3.17 => 0.3.17 
    typescript: ^5.1.3 => 5.4.5 
    zod: ^3.23.4 => 3.23.4 
    zustand: ^4.5.2 => 4.5.2 
  npmGlobalPackages:
    corepack: 0.18.0
    npm: 9.6.7

Describe the bug

I'm trying to get all the records in my db filtering by lat and lng, (Float fields) I have a range for each field (lat, lng)

This is my query statement:

const { data } = await client.graphql({
        query: listAffiliates,
        variables: {
          filter: {
            and: [
              {
                lat: {
                  between: [
                    minLat,
                    maxLat,
                  ]
                }
              },
              {
                lng: {
                  between: [
                    minLng,
                    maxLng,
                  ]
                }
              },
            ]
          }
        }
      });

Even doing this doesn't seems to work:

lat: {
    eq: 36.77676,
}

My data without any filtering is this one so it should work:

[{"__typename": "Affiliate", "address": "***", "businessHours": "{\"monday\":{\"from\":\"09:00 am\",\"to\":\"07:00 pm\"}}", "category": null, "coupons": {"items": [Array]}, "coverPicture": null, "createdAt": "2024-04-30T04:39:21.263Z", "description": "Cenaduría", "id": "218b239b-42ee-4392-8a42-c38008c2201f",  "lat": 36.77676, "lng": -115.56526, "name": "Tortas La Panzona", "profilePicture": "profile-picture/a4a88488-b041-70ed-e1ff-127fd80eea4d_6350A80E-0A3F-49A5-8774-09FD97F5BB86.jpg", "reviews": {"items": [Array]}, "updatedAt": "2024-04-30T04:46:31.671Z", "userId": "a4a88488-b041-70ed-e1ff-127fd80eea4d"}, {"__typename": "Affiliate", "address": "***", "businessHours": "{\"monday\":{\"from\":\"11:00 am\",\"to\":\"12:00 pm\"},\"tuesday\":{\"from\":\"11:00 am\",\"to\":\"12:00 pm\"},\"thursday\":{\"from\":\"09:00 am\",\"to\":\"11:00 pm\"},\"Lunes\":{\"from\":\"10:00 am\",\"to\":\"04:00 pm\"}}", "category": "Restaurante Bar", "coupons": {"items": [Array]}, "coverPicture": "cover-picture/14784418-40e1-703f-6058-37f638350ebf_0AC2B4A9-DDBD-4E4D-AFF4-1442A5877843.jpg", "createdAt": "2024-04-30T04:31:08.823Z", "description": "Cenaduría", "id": "17989f6d-2e5f-49a9-b529-f55d894cc496", "lat": 36.77676, "lng": -115.56526, "name": "Tortas El Panzón", "profilePicture": "profile-picture/14784418-40e1-703f-6058-37f638350ebf_959090CF-944A-4363-B042-975373E3AB60.jpg", "reviews": {"items": [Array]}, "updatedAt": "2024-05-10T23:36:32.447Z", "userId": "14784418-40e1-703f-6058-37f638350ebf"}]

Expected behavior

Filter the records in my db in order to get the nearest to the user.

Reproduction steps

  1. initialize a new amplify project.
  2. create a model with a Int field.
  3. create a record for this model and enter a negative number in this numeric field
  4. try to filter this record by its numeric field using a couple negative values.
  5. face the error.

Code Snippet

// Put your code below this line.
const { data } = await client.graphql({
        query: listAffiliates,
        variables: {
          filter: {
            and: [
              {
                lat: {
                  between: [
                    minLat,
                    maxLat,
                  ]
                }
              },
              {
                lng: {
                  between: [
                    minLng,
                    maxLng,
                  ]
                }
              },
            ]
          }
        }
      });
GraphQL model
type Affiliate @model {
  id: ID!
  name: String!
  lat: Float! @index
  lng: Float! @index
...other fields
}

Log output

// Put your logs below this line


aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

Iphone 15 pro Simulator

Mobile Operating System

IOS 17.4

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

@fimbres fimbres added the pending-triage Issue is pending triage label May 13, 2024
@cwomack cwomack added the GraphQL Related to GraphQL API issues label May 13, 2024
@fimbres
Copy link
Author

fimbres commented May 15, 2024

Good morning @cwomack, any luck on this one?

@fimbres
Copy link
Author

fimbres commented May 17, 2024

Hey @cwomack, did you have any chance to take a look at this one?

@chrisbonifacio chrisbonifacio self-assigned this May 18, 2024
@chrisbonifacio chrisbonifacio added the to-be-reproduced Used in order for Amplify to reproduce said issue label May 20, 2024
@chrisbonifacio
Copy link
Member

chrisbonifacio commented May 20, 2024

Hi, @fimbres 👋 Sorry for the delayed response. Thank you for raising this issue!

I will be reproducing this issue and report back soon to mark as a bug or explain any findings

@fimbres
Copy link
Author

fimbres commented May 20, 2024

No worries @chrisbonifacio, thank you so much for helping!

@chrisbonifacio
Copy link
Member

chrisbonifacio commented May 22, 2024

Hi @fimbres I deployed the same schema but I don't think I ran into any issues while trying to query and filter using numbers.

Here's my first query:

const { data } = await client.graphql({
  query: listAffiliates,
  variables: {
    filter: {
      and: [
        {
          lat: {
            between: [0, 40],
          },
        },
        {
          lng: {
            between: [-300, -100],
          },
        },
      ],
    },
  },
});

and the result:

image

I changed the lat filter to:

lat: {
  between: [0, 20],
},

and the result was no data, as expected:

image

Also doing eq seems to work:

const { data } = await client.graphql({
  query: listAffiliates,
  variables: {
    filter: {
      and: [
        {
          lat: {
            eq: 36.77676,
          },
        },
        {
          lng: {
            eq: -115.56526,
          },
        },
      ],
    },
  },
});

Same result as first query.

Can you share more details about the values you're using to filter for records?

@chrisbonifacio chrisbonifacio added not-reproducible Not able to reproduce the issue question General question pending-response and removed to-be-reproduced Used in order for Amplify to reproduce said issue pending-triage Issue is pending triage labels May 22, 2024
@fimbres
Copy link
Author

fimbres commented May 22, 2024

Interesting, yes as I said previously this is my data

[{"__typename": "Affiliate", "address": "***", "businessHours": "{\"monday\":{\"from\":\"09:00 am\",\"to\":\"07:00 pm\"}}", "category": null, "coupons": {"items": [Array]}, "coverPicture": null, "createdAt": "2024-04-30T04:39:21.263Z", "description": "Cenaduría", "id": "218b239b-42ee-4392-8a42-c38008c2201f",  "lat": 36.77676, "lng": -115.56526, "name": "Tortas La Panzona", "profilePicture": "profile-picture/a4a88488-b041-70ed-e1ff-127fd80eea4d_6350A80E-0A3F-49A5-8774-09FD97F5BB86.jpg", "reviews": {"items": [Array]}, "updatedAt": "2024-04-30T04:46:31.671Z", "userId": "a4a88488-b041-70ed-e1ff-127fd80eea4d"}, {"__typename": "Affiliate", "address": "***", "businessHours": "{\"monday\":{\"from\":\"11:00 am\",\"to\":\"12:00 pm\"},\"tuesday\":{\"from\":\"11:00 am\",\"to\":\"12:00 pm\"},\"thursday\":{\"from\":\"09:00 am\",\"to\":\"11:00 pm\"},\"Lunes\":{\"from\":\"10:00 am\",\"to\":\"04:00 pm\"}}", "category": "Restaurante Bar", "coupons": {"items": [Array]}, "coverPicture": "cover-picture/14784418-40e1-703f-6058-37f638350ebf_0AC2B4A9-DDBD-4E4D-AFF4-1442A5877843.jpg", "createdAt": "2024-04-30T04:31:08.823Z", "description": "Cenaduría", "id": "17989f6d-2e5f-49a9-b529-f55d894cc496", "lat": 36.77676, "lng": -115.56526, "name": "Tortas El Panzón", "profilePicture": "profile-picture/14784418-40e1-703f-6058-37f638350ebf_959090CF-944A-4363-B042-975373E3AB60.jpg", "reviews": {"items": [Array]}, "updatedAt": "2024-05-10T23:36:32.447Z", "userId": "14784418-40e1-703f-6058-37f638350ebf"}]

If I filter this data based either on lat or lng properties (Float) I don't get any data back, even doing eq or between statements.

I don't know if this can be related with my migration from string to float field type (because previously both fields were String types) maybe in the migration process something was missing?

Should I try deleting this two fields and then reading them with the correct field type?

@fimbres
Copy link
Author

fimbres commented May 22, 2024

Or perhaps it's something related with the @searchable tag that previously I added to the Affiliate model

type Affiliate @model @searchable {
  id: ID!
  name: String!
  description: String!
  address: String!
  lat: Float! @index
  lng: Float! @index
  businessHours: String
  profilePicture: String!
  coverPicture: String
  category: String
  state: String
  stripeAccountId: String
  userId: ID! @index
}

@fimbres
Copy link
Author

fimbres commented May 23, 2024

@chrisbonifacio I have an update, now I'm able to see one of the two records coming back from the numeric filter, but as you can see both of the records have the same cords. Do you have any idea on why is this happening?

try {
      const { data } = await client.graphql({
        query: listAffiliatesAndCoupons,
        variables: {
          filter: {
            and: [
              {
                lat: {
                  between: [
                    minLat, 
                    maxLat
                  ],
                },
              },
              {
                lng: {
                  between: [
                    minLng, 
                    maxLng,
                  ],
                },
              },
            ],
          },
        },
      });

data returning:
[{"__typename": "Affiliate", "createdAt": "2024-04-30T04:31:08.823Z", "description": "Cenaduría", "id": "17989f6d-2e5f-49a9-b529-f55d894cc496", "lat": 36.77676, "lng": -115.56526, "name": "Tortas El Panzón", "reviews": {"items": [Array]}, "stripeAccountId": "***", "updatedAt": "2024-05-15T22:45:51.828Z", "userId": "14784418-40e1-703f-6058-37f638350ebf"}]

@chrisbonifacio
Copy link
Member

Can you check the network activity in your browser, search for the graphql request in the Network tab, and share the payload that was sent? Just want to be certain of the values being passed for the filter expression.

@chrisbonifacio
Copy link
Member

chrisbonifacio commented May 24, 2024

also do you still have searchable enabled? what is the current schema you're using?

There is an issue I remember regarding OpenSearch and unexpected results with floats in particular:

aws-amplify/amplify-category-api#866

Relevant takeaways from the reproduction of that issue:

  1. Check in the OpenSearch instance that the index for your lat and lng fields are being parsed as a float and not a long
  2. The index is created in the OpenSearch instance based on the first data point that is inserted (I think this is the case as an index doesn't exist before the data is inserted).

@fimbres
Copy link
Author

fimbres commented May 24, 2024

Sure thing, this is the payload:

query ListAffiliatesAndCoupons($filter: ModelAffiliateFilterInput, $limit: Int, $nextToken: String) {
  listAffiliates(filter: $filter, limit: $limit, nextToken: $nextToken) {
    items {
      id
      name
      description
      address
      lat
      lng
      businessHours
      profilePicture
      coverPicture
      category
      stripeAccountId
      userId
      createdAt
      updatedAt
      __typename
      coupons {
        items {
          id
          title
          description
          stock
          coverPicture
          price
          regularPrice
          startDate
          endDate
          renovationDays
          categories
          createdAt
          affiliate {
            id
            name
            category
            stripeAccountId
            reviews {
              items {
                score
              }
            }
          }
        }
      }
      reviews {
        items {
          title
          message
          score
          createdAt
          user {
            name
            profilePicture
          }
        }
      }
    }
    nextToken
    __typename
  }
}

"variables": {
    "filter": {
        "and": [
            {
                "lat": {
                    "between": [
                        34.08990684711976,
                        36.659519152880236
                    ]
                }
            },
            {
                "lng": {
                    "between": [
                        -117.52847091173753,
                        -115.21013908826246
                    ]
                }
            }
        ]
    }
}

@fimbres
Copy link
Author

fimbres commented May 24, 2024

Right now it's enabled, this is the model:

type Affiliate @model @searchable {
  id: ID!
  name: String!
  description: String!
  address: String!
  lat: Float! @index
  lng: Float! @index
  businessHours: String
  profilePicture: String!
  coverPicture: String
  category: String
  state: String
  stripeAccountId: String
  userId: ID! @index
}

But I'm not using the searchable query, I'm using a custom query. in my OpenSearch instance I don't have any record. I think it's because I did not added any Affiliates record after this instance was created.

if I remove the @searchable tag from the model, should I still be able to query based on lat & lng?

@fimbres
Copy link
Author

fimbres commented May 25, 2024

@chrisbonifacio I just removed @searchable but nothing changed

@fimbres
Copy link
Author

fimbres commented Jun 12, 2024

Any idea on this one @chrisbonifacio ?

@chrisbonifacio
Copy link
Member

Hi @fimbres apologies for the wait. We haven't been able to reproduce this issue internally.

If you're still experiencing this issue I would try testing the same query in the AppSync console and see if you get the same behavior and also in the DynamoDB console. This would rule out whether it's an issue with Amplify's resolvers, library, or if the issue is occurring at the database level.

Might also be worth trying to reproduce on a fresh project.

@chrisbonifacio
Copy link
Member

chrisbonifacio commented Jun 24, 2024

@fimbres one other possible thing that could be preventing one record from being returned and not another that should match the filter expression, is a difference in authorization rules or owners. Can you share what authorization rules might be on the model to confirm?

Can you also check the response for a nextToken field? It's also possible that the other record(s) were paginated.

@chrisbonifacio
Copy link
Member

Hi 👋 Closing this as we have not heard back from you. If you are still experiencing this issue and in need of assistance, please feel free to comment and provide us with any information previously requested by our team members so we can re-open this issue and be better able to assist you.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GraphQL Related to GraphQL API issues not-reproducible Not able to reproduce the issue question General question
Projects
None yet
Development

No branches or pull requests

3 participants