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

feat: warn in development mode when query is missing paging or explicit fields #788

Merged
merged 3 commits into from
Mar 10, 2021

Conversation

amcgee
Copy link
Member

@amcgee amcgee commented Mar 3, 2021

Eventually we may want to forbid unpaged and ambiguous (no fields specified or dynamic * / :owner used) in the runtime. That is likely going to take some time to enforce outright, so this change simply deprecates those features and shows a warning in development mode (hidden in production). This should help us identify and weed out problematic queries in our apps and libraries.

Due to the nature of our API we might not be able to enforce this across all endpoints (many endpoints don't have fields or paging as an option at all). As such, this might initially have quite a few "false positives", but we can use those cases to identify and "exempt" the non-normative endpoints from this validation here. The field and paging requirements apply mostly to metadata resources which follow a more traditional REST pattern.

Screen Shot 2021-03-03 at 17 37 34
Screen Shot 2021-03-03 at 17 36 42

@amcgee amcgee requested a review from a team March 3, 2021 16:47
Copy link
Contributor

@HendrikThePendric HendrikThePendric left a comment

Choose a reason for hiding this comment

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

In the current state of the webapi, we can’t assume the presence of full PATCH support, and we cannot rely on PUT requests with mergeMode=MERGE to correctly do partial updates. As such the recommended approach for "partial updates" is:

  • GET all owned fields
  • Allow editing a subset of these fields
  • Update via a PUT with default mergeMode, which is REPLACE, and make sure the owned fields that were not updated are also included in the request payload.

As such, I think we should NOT show this warning for the :owner field filter right now.

I hope the webapi get full PATCH support at some point and we can start showing warning for :owner as well.

Copy link
Contributor

@HendrikThePendric HendrikThePendric left a comment

Choose a reason for hiding this comment

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

After discussing things we agreed to keep the warning but use a custom message for the :owner filter to explain it can be required in some situations. That seems like a good solution to me.

@amcgee
Copy link
Member Author

amcgee commented Mar 9, 2021

I think we should restrict the scope of this change to the resources which we know for sure support paging - that's at minimum 77 of the 88 metadata resources listed at /api/resources (possibly more, like trackedEntityInstances, which just don't respond to global collection GETs)

This will avoid noise for resources which don't support paging at all, and these are likely the same resources which support fields parameters - I haven't written a script to test this yet.

@amcgee amcgee merged commit 5f28c79 into master Mar 10, 2021
@amcgee amcgee deleted the feat-warn-paging-fields branch March 10, 2021 16:25
dhis2-bot added a commit that referenced this pull request Mar 10, 2021
# [2.8.0](v2.7.1...v2.8.0) (2021-03-10)

### Features

* warn in development mode when  query is missing paging or explicit fields ([#788](#788)) ([5f28c79](5f28c79))
@dhis2-bot
Copy link
Contributor

🎉 This PR is included in version 2.8.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants