notum-cz / strapi-plugin-location

This plugin allows users to create location inputs and store latitude and longitude values as geometry types in a PostGIS database. It also provides functionality to filter items based on their location.
MIT License
26 stars 13 forks source link

Error: Undefined attribute level operator 0 #74

Open Ademboussetha opened 1 year ago

Ademboussetha commented 1 year ago

Issue Description

When making a request to the Strapi plugin with the $location[coords] parameter, I've observed an issue where if I set the radius to a value greater than 406, it results in an error: Error: Undefined attribute level operator 0. Upon further investigation, it seems that this error is related to a change in the data type of the variable when the array of IDs contains a large number of elements.

Steps to Reproduce

  1. Make a request with the following parameters: ?$location[coords]=40.848557,14.255131,406.
  2. Observe the error: Error: Undefined attribute level operator 0.

Expected Behavior

The plugin should handle requests with a radius greater than 406 without producing an error.

Additional Information

I noticed that when the array of IDs becomes large, the data type of the variable appears to change from an array of numbers to an array of objects. This transition in data types may be the root cause of the issue.

Environment

Please let me know if you need any more information or if there are specific steps to reproduce the issue.

Screenshots

image

omikulcik commented 1 year ago

Hi @Ademboussetha, thank you for reporting this issue you have encountered. Unfortunately, I have not been able to reproduce it.

I created 26 entries (default response length is 25 entries) and performed a request with a perimeter of 5000. See screenshot.

image

Everything worked as expected with no error. Could you please provide more info how I could reproduce the behaviour you are enctoutering?

Thank You :)

Ademboussetha commented 1 year ago

Hello @omikulcik,

I appreciate your prompt response.

To replicate the error effectively, it might be beneficial to populate your collections with a larger number of elements. In my particular scenario, specifying a range of "450" for instance, results in a total of 500 rows of data being returned. However, it appears that in your case, only 26 rows are being returned.

Hence, I recommend augmenting the entries within your collection to accurately reproduce the issue.

Thank you for your attention to this matter. Please let me know if you need any more information.

omikulcik commented 1 year ago

I was successful replicating the bug. However, I do not know how to fix it. It seems that even if I change the scructure back to array it transforms back to object somehow. Will get back to it later. image

omikulcik commented 1 year ago

@Ademboussetha Just FYI I have discussed this with our senior Strapi developer and even he was not able to solve it so we will contact someone from Strapi.

Ademboussetha commented 1 year ago

@omikulcik I've come up with a solution, but it's more of a workaround that involves processing the array in chunks of 100 at a time.

omikulcik commented 1 year ago

@Ademboussetha You can submit a PR with the solution if you want. We have discussed this with Strapi and the are unsure why this might be happening. They think it might be a bug in Koa which is a dependency of Strapi.