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

fix(api): return total count on related endpoint #16397

Merged
merged 2 commits into from
Aug 24, 2021

Conversation

villebro
Copy link
Member

SUMMARY

While reviewing/testing #16144 , I came across a TODO related to the /related endpoints not returning total object count, but rather the count of results on the requested page.

This PR makes the following changes:

  • When include_ids is undefined, always return the total number of objects as the count parameter as opposed to the actual number of objects in result.
  • When include_ids is defined, behavior is unchanged, i.e. count equals the length of result.
  • When include_ids is defined and page > 0, a 400 is returned due to pagination of mixed results not being possible.

BEFORE

Currently the count parameter in the response is equal to the length of the result array (in this example, the total number of objects is in fact two, not just one):
image

AFTER

Now the count parameter shows the total number of objects, despite the page size being less:
image

When sending the request with include_ids and page=0, the result is the same as before (notice how page_size only affects the values not included in include_ids):
image

Now requesting other than the first page with defined include_ids will result in a 400:
image

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

ids = args.get("include_ids")
if page and ids:
# pagination with forced ids is not supported
return self.response_400()
Copy link
Member

@michael-s-molina michael-s-molina Aug 23, 2021

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good idea - will update 👍

@codecov
Copy link

codecov bot commented Aug 24, 2021

Codecov Report

Merging #16397 (c108922) into master (970d762) will decrease coverage by 0.30%.
The diff coverage is 67.62%.

❗ Current head c108922 differs from pull request most recent head dc8a4b9. Consider uploading reports for the commit dc8a4b9 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master   #16397      +/-   ##
==========================================
- Coverage   76.64%   76.33%   -0.31%     
==========================================
  Files        1000     1000              
  Lines       53489    53491       +2     
  Branches     6816     6818       +2     
==========================================
- Hits        40996    40834     -162     
- Misses      12257    12419     +162     
- Partials      236      238       +2     
Flag Coverage Δ
hive ?
mysql 81.49% <85.59%> (+<0.01%) ⬆️
postgres 81.55% <86.55%> (+<0.01%) ⬆️
presto ?
python 81.64% <86.55%> (-0.42%) ⬇️
sqlite 81.20% <85.59%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...c/views/CRUD/data/database/DatabaseModal/index.tsx 44.24% <0.00%> (-0.12%) ⬇️
superset/charts/commands/importers/dispatcher.py 80.64% <ø> (ø)
superset/cli.py 52.85% <0.00%> (ø)
superset/commands/importers/v1/__init__.py 94.73% <ø> (ø)
superset/commands/importers/v1/examples.py 39.53% <ø> (ø)
superset/common/tags.py 0.00% <0.00%> (ø)
superset/dashboards/api.py 93.03% <ø> (ø)
...perset/dashboards/commands/importers/dispatcher.py 83.87% <ø> (ø)
superset/dashboards/commands/importers/v0.py 89.94% <ø> (ø)
superset/dashboards/schemas.py 99.37% <ø> (ø)
... and 80 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 970d762...dc8a4b9. Read the comment docs.

@zhaoyongjie zhaoyongjie self-requested a review August 24, 2021 05:37
Copy link
Member

@zhaoyongjie zhaoyongjie left a comment

Choose a reason for hiding this comment

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

Tested in my local environment, LGTM. Thanks for the improvement.

@villebro villebro merged commit f6637ca into apache:master Aug 24, 2021
@villebro villebro deleted the villebro/paginate-related branch August 24, 2021 12:13
opus-42 pushed a commit to opus-42/incubator-superset that referenced this pull request Nov 14, 2021
* fix(api): return total count on related endpoint

* update response code from 400 to 422
QAlexBall pushed a commit to QAlexBall/superset that referenced this pull request Dec 28, 2021
* fix(api): return total count on related endpoint

* update response code from 400 to 422
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.4.0 labels Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels preset-io size/M 🚢 1.4.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants