API: filter to get one-sided Tolerance

Issue #530 open
Vincent Leduc created an issue

Hi Randle,

This may not be an real issue, but I can’t figure out how I should make a GET request to the API for a one-sided tolerance.

My first try was to use a request with __isnull, such as in the following screenshot:

As you can see, the API returned a double-sided Tolerance and ignored my act_low__isnull=True and my tol_low__isnull=True.

So I had a look in the source code, and it looks like the Tolerance filter does not support __isnull?

class ToleranceFilter(filters.FilterSet):

    type = filters.Filter(
        widget=widgets.Select(choices=[('', 'Any')] + list(models.TOL_TYPE_CHOICES)),

    class Meta:
        model = models.Tolerance
        fields = {
            "name": ['icontains', 'in'],
            "act_low": ['exact', 'in', 'gte', 'lte'],
            "tol_low": ['exact', 'in', 'gte', 'lte'],
            "tol_high": ['exact', 'in', 'gte', 'lte'],
            "act_high": ['exact', 'in', 'gte', 'lte'],
            "mc_pass_choices": ['icontains', 'in'],
            "mc_tol_choices": ['icontains', 'in'],
            "bool_warning_only": ['exact'],

I created a one-sided Tolerance that should match my filter, and tried a request using =null, thinking about using the exact match, but didn’t have any success:

Thanks for your help!

Comments (4)

  1. Randle Taylor
    • changed status to open

    Hi Vincent,

    Thanks for reporting this. I assumed that the ‘exact’ filter would allow filtering for null/None values but frustratingly it looks like that's not the case and the filter fields need to specify ‘isnull’ explicitly.

    I guess a workaround is just to request all the tolerance objects and then filter them client side e.g.:

    resp = requests.get(api + "/qa/tolerances/", headers=headers)
    one_sided = [tol for tol in resp.json()['results'] if tol['act_high'] is None]
  2. Vincent Leduc reporter

    Thanks. I figured that out and it’s indeed a valid workaround. I just couldn’t find a way to craft a request that gave me the expected results, and thought maybe I was missing something.

  3. Log in to comment