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

Api - filter favorite in /resources endpoint doesn't return all favorites item #216

Closed
luorlandini opened this issue Jun 10, 2021 · 3 comments
Assignees
Labels
API v2 bug Something isn't working

Comments

@luorlandini
Copy link

This endpoint:

api/v2/resources?favorite=true

seems not to return all items, analyzing the case, it seems not to return those added by this api:

api/v2/resources/{id}/favorite

In the video I simulate the case, adding an item, in total, my account has 3 favorites

Registrazione.schermo.2021-06-10.alle.10.19.31.mov

the api return one item

Registrazione.schermo.2021-06-10.alle.10.21.50.mov
@luorlandini luorlandini added bug Something isn't working API v2 labels Jun 10, 2021
@mattiagiupponi
Copy link
Contributor

After some analysis, the bug is caused by a 'wrong' categorization of the content_type in the Favorite table.

From the api/v2/resources/{id}/favorite endpoint, the content_type of the resource is set as resourcebase in the favorite table, while from the Layer/Document/app table, is correctly assigned -> ['document', 'geostory', 'map', 'layer']

So this means that the FavoriteFilter when is called, filter for the resource_type available in the queryset (for reducing the weight of the query)

ctype = list(set([r.resource_type for r in queryset]))
return queryset.filter(
    pk__in=Subquery(
        Favorite.objects.values_list("object_id", flat=True)
        .filter(user=request.user)
        .filter(content_type__model__in=ctype)
    )
)

So if the item has a content_type = layer in the queryset and resourcebase in the favorite table, it will always be excluded from the return value.

Three possible solutions:

  • Remove the filter filter(content_type__model__in=ctype) since we must rely to the Layer/Document/GeoApp
  • Find a way to fix the Favorite endpoint in order to store the correct value
  • Remove the content_type from the favorite table, since the response from the API passes through the ResourceBaseSerializer

@giohappy what do you think?

@giohappy
Copy link
Contributor

@mattiagiupponi I would be in favour og getting rid of the content_type field, but in this case I guess we need to adapt the rest of GeoNode (templates, etc.). If you think this is doable let's go on with this.
Otherwise we will need to fix the filter endpoint to store the correct content type.

@mattiagiupponi
Copy link
Contributor

In order to reduce as much as possible regression issues, I just fix the content_type saved from the API.
Here is the relatives:
Geonode issue: GeoNode/geonode#7644
Master PR: GeoNode/geonode#7645
Backport PR: GeoNode/geonode#7646

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API v2 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants