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 grouping counts #353

Merged
merged 7 commits into from
Jul 13, 2021
Merged

Fix grouping counts #353

merged 7 commits into from
Jul 13, 2021

Conversation

eito-fis
Copy link
Contributor

Fixes #352

Updates the record endpoint to have proper grouping behaviors.

Technical details
Updates the get_group_counts() function to create a subquery with the appropriate parameters applied, before grouping on the result. Also updates the limit offset tests and adds a new filtering + grouping test.

Checklist

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the master branch of the repository
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no
    visible errors.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@kgodey
Copy link
Contributor

kgodey commented Jul 12, 2021

@eito-fis Please see the new format suggestion in the issue (comma separation of values could be confusing, since values can have commas in them).

@@ -67,7 +67,8 @@ def paginate_queryset(self, queryset, request, table_id,
filters=filters, order_by=order_by
)
# Convert the tuple keys into strings so it can be converted to JSON
group_count = {','.join(k): v for k, v in group_count.items()}
group_count = [{"columns": list(cols), "count": count}
Copy link
Contributor

Choose a reason for hiding this comment

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

@eito-fis On second thought, I think changing this key to values instead of columns makes more sense, these aren't column names.

@eito-fis eito-fis requested a review from kgodey July 13, 2021 19:17
Copy link
Contributor

@kgodey kgodey left a comment

Choose a reason for hiding this comment

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

@eito-fis I tested this locally by going to http://localhost:8000/api/v0/tables/2/records/?group_count_by%3D[%22Status%22] in my browser and I'm getting

    "group_count": {
        "group_count_by": null,
        "results": null
    },

It should be returning the group count for the Status column, right? Am I accessing the API correctly?

@eito-fis
Copy link
Contributor Author

@eito-fis I tested this locally by going to http://localhost:8000/api/v0/tables/2/records/?group_count_by%3D[%22Status%22] in my browser and I'm getting

    "group_count": {
        "group_count_by": null,
        "results": null
    },

It should be returning the group count for the Status column, right? Am I accessing the API correctly?

That's strange, running client.get(f'/api/v0/tables/{table.id}/records/?group_count_by=["Status"]') in a test returns:

'group_count': {
    'group_count_by': ['Status'],
    'results': [
        {'values': ['Issued'], 'count': 48},
        {'values': ['Application'], 'count': 2}
    ]
}

Are the tests passing for you?

@kgodey
Copy link
Contributor

kgodey commented Jul 13, 2021

@eito-fis The tests are passing for me. Do you get the same result when you go the URL in your browser?

@kgodey
Copy link
Contributor

kgodey commented Jul 13, 2021

@eito-fis I figured out the issue. When I replace the %3D with =, it works fine. It looks like you'll need to handle URL encoding correctly.

Copy link
Contributor

@kgodey kgodey left a comment

Choose a reason for hiding this comment

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

@eito-fis Looks good overall, nice work. Please handle URL encoding correctly and also add a test for it so that we don't break it in the future.

@eito-fis
Copy link
Contributor Author

@kgodey After looking around a bit, I think this is desired behavior? it seems like the = character is reserved to separate keys and values in the url, and shouldn't be encoded when being used for that purpose.

@kgodey
Copy link
Contributor

kgodey commented Jul 13, 2021

@eito-fis I think you're correct. I probably ended up with that URL because I mistyped the query to begin with and my browser got confused by the =. Sorry for the false alarm.

@kgodey kgodey merged commit a6267e0 into master Jul 13, 2021
@kgodey kgodey deleted the fix_grouping_counts branch July 13, 2021 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Undesirable record grouping behaviours
2 participants