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

⚡️ Disable pagination when requesting form definitions in the admin #3542

Merged
merged 4 commits into from
Oct 24, 2023

Conversation

Viicos
Copy link
Contributor

@Viicos Viicos commented Oct 18, 2023

Fixes #3491

I'm a bit frustrated by this issue, as what I wanted to do initially was:

  • Be able to specify specific fields to include via query parameters, e.g. path?include=url,name,internal_name (as only these three fields are required by the NewStepFormDefinitionPicker component)
  • Disable pagination in some way

First one would be doable with https://github.com/wimglenn/djangorestframework-queryfields but it would add an extra dependency not updated in 7 years.

Or another solution suggested by @joeribekker:

  • Define a custom endpoint (e.g. via @action) to only fetch the required fields, but it would not inherit from the currently defined filterset_class.

I ended up using a custom pagination class, that would understand page_size=0 to mean no pagination. We will have to see if this is viable with a lot of form definitions in the db

@Viicos Viicos force-pushed the issue/3491-form-definitions-fetching branch 2 times, most recently from f745aab to 6c6b746 Compare October 18, 2023 10:36
@Viicos Viicos force-pushed the issue/3491-form-definitions-fetching branch from 9e641a4 to 2ecce2a Compare October 18, 2023 11:02
@Viicos
Copy link
Contributor Author

Viicos commented Oct 19, 2023

I think we can get rid of this?

def filter_queryset(self, queryset):
"""
Override base implementation to add OR-behaviour instead of the standard AND.
See https://github.com/carltongibson/django-filter/discussions/1426
"""
_or = Q()
for name in self.Meta.or_fields:

@codecov
Copy link

codecov bot commented Oct 19, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (dd45e7f) 95.92% compared to head (91a4dd4) 95.92%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3542   +/-   ##
=======================================
  Coverage   95.92%   95.92%           
=======================================
  Files         670      670           
  Lines       21527    21529    +2     
  Branches     2485     2485           
=======================================
+ Hits        20649    20651    +2     
  Misses        609      609           
  Partials      269      269           
Files Coverage Δ
src/openforms/forms/api/filters.py 94.44% <100.00%> (+0.32%) ⬆️
src/openforms/forms/api/viewsets.py 99.14% <ø> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sergei-maertens
Copy link
Member

I think we can get rid of this?

def filter_queryset(self, queryset):
"""
Override base implementation to add OR-behaviour instead of the standard AND.
See https://github.com/carltongibson/django-filter/discussions/1426
"""
_or = Q()
for name in self.Meta.or_fields:

we can deprecate it, but removing it is a breaking change and requires a new major version of the API

@Viicos
Copy link
Contributor Author

Viicos commented Oct 20, 2023

Couldn't get e2e tests to work. My best guess (and I was able to reproduce only once locally but unfortunately the timeout closed the test browser) is that this happens when form definitions are loaded, and the e2e test clicks on the select element on a precise timing where the select options HTML elements don't have time to load, which kind of breaks React's reactivity.

Edit: I'm able to reproduce ~ 1/5th of the time, but can't really do much as console isn't opened on startup and I can't see the requests made.

Dirty solution: page.wait_for_timeout

@Viicos Viicos added the blocked label Oct 20, 2023
@Viicos Viicos force-pushed the issue/3491-form-definitions-fetching branch from e914693 to a5ad3f8 Compare October 23, 2023 11:01
@Viicos Viicos removed the blocked label Oct 23, 2023
Copy link
Member

@sergei-maertens sergei-maertens left a comment

Choose a reason for hiding this comment

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

Can you also deprecate that filter_queryset thing doing the OR filter? A warnings.warn(..., DeprecationWarning) is fine & add it to the list of things to remove in #3283

@Viicos
Copy link
Contributor Author

Viicos commented Oct 23, 2023

Can you also deprecate that filter_queryset thing doing the OR filter? A warnings.warn(..., DeprecationWarning) is fine & add it to the list of things to remove in #3283

Shouldn't we deprecate the OpenAPI query parameters instead? Or you only want the OR filter to have a warnings.warn to not forgot removing it when #3283 gets tackled?

@sergei-maertens
Copy link
Member

Can you also deprecate that filter_queryset thing doing the OR filter? A warnings.warn(..., DeprecationWarning) is fine & add it to the list of things to remove in #3283

Shouldn't we deprecate the OpenAPI query parameters instead? Or you only want the OR filter to have a warnings.warn to not forgot removing it when #3283 gets tackled?

Only the OR filter behaviour, the query params themselves are obviously still used, just not at the same time (anymore).

Copy link
Member

@sergei-maertens sergei-maertens left a comment

Choose a reason for hiding this comment

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

Please rebase your PR in a couple of atomic commits :) then it's good to merge!

@Viicos Viicos force-pushed the issue/3491-form-definitions-fetching branch from 9659ca9 to 3bea98b Compare October 24, 2023 07:31
@Viicos Viicos force-pushed the issue/3491-form-definitions-fetching branch from 3bea98b to 91a4dd4 Compare October 24, 2023 07:33
@Viicos Viicos mentioned this pull request Oct 24, 2023
23 tasks
@sergei-maertens sergei-maertens merged commit 7d0c223 into master Oct 24, 2023
@sergei-maertens sergei-maertens deleted the issue/3491-form-definitions-fetching branch October 24, 2023 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Slowdown due to reusable form defintions lookup when loading/starting a form.
2 participants