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 queryset for DateRangeFilter when field_path (related field name)… #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ecoulon98
Copy link

… starts with a 'd', 'r', 'f', '_'.

Bug due to the use of lstrip(). Replaced by a simple regular expression to delete the 'drf__' filter prefix from the left (sort of left replace).

… starts with a 'd', 'r', 'f', '_'.

Bug due to the use of lstrip(). Replaced by a simple regular expression to delete the 'drf__' filter prefix from the left (sort of left replace).
@yeago
Copy link
Collaborator

yeago commented Jan 4, 2018

what was the bug?

@ecoulon98
Copy link
Author

The bug is that when you apply the DateRangeFilter to a field that starts with 'd', 'r', 'f', or '_' (for example 'date_of_operation'), the lstrip() used in the queryset() call will not only remove the FILTER_PREFIX ('drf__'), but also any characters of your own field name that match the FILTER_PREFIX characters from FILTER_PREFIX.

In the case of a field name such as 'date_of_operation', the variable "lookup_upto" will be set to 'ate_of_operation' (WRONG). causing to not find the parameter in filter_params, and not being able to add the datetime delta of one day to have a correct queryset.

It is because lstrip() will iterate the characters of the string (FILTER_PREFIX), rather than taking the entire string.

How to reproduce the issue:

  • Apply in the Admin (list_filter) the DateRangeFilter to a field that starts with the letters 'd', 'r', 'f' or '_'.
  • When applying the date range filter "date to" to a specific date, you will always miss the last day of data (the data of that specific date).

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.

2 participants