django-url-filter icon indicating copy to clipboard operation
django-url-filter copied to clipboard

UUID filter with lookup startswith

Open rodrigondec opened this issue 3 years ago • 4 comments

Resume

My application uses UUIDField as a primary key. So every model inherit

class BaseModel(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)

I want to filter by this id!

ID filter

It's possible do filter by ID.

So we can do a request like

/some_model_resource/?id={COMPLETE-UUID-HERE}

And it works :tada: !

ID startswith filter

statswith is a supported lookup on url-filters!

https://github.com/miki725/django-url-filter/blob/1585da89acf9f182f8db2534ab8c72e89c5c92f2/url_filter/backends/django.py#L22-L48

So it should be possible do a request like

/some_model_resource/?id__startswith={INCOMPLETE-UUID-HERE}

It doens't work :-1:

The problem

The filter calls the django form clean!

https://github.com/miki725/django-url-filter/blob/1585da89acf9f182f8db2534ab8c72e89c5c92f2/url_filter/filters.py#L335-L353

REMEMBER, I'm passing a incomplete UUID because the goal is to search with the first part of the UUID with the lookup startswith!

This causes the django.forms.fields.UUIDField.clean method to raise a ValidationError!

https://github.com/django/django/blob/a7e7043c8746933dafce652507d3b821801cdc7d/django/forms/fields.py#L1211

rodrigondec avatar Nov 19 '21 15:11 rodrigondec

I'm willing to open a PR

I just need to know with which approach this should be resolved with.

Should it be added try/except on the form cleanup?

Should be created some engineering to allow 'partial values` with specific lookups (startswith, istartswith, endswith, iendswith, icontains, contains)?

Should this be treated only for UUID Fields?

rodrigondec avatar Nov 19 '21 15:11 rodrigondec

@miki725 friendly ping

rodrigondec avatar Nov 22 '21 19:11 rodrigondec

I think the maintener has died, just look at the pull requests session...

felps-dev avatar Nov 25 '21 16:11 felps-dev

I think the maintener has died, just look at the pull requests session...

Sad life :cry:

rodrigondec avatar Dec 07 '21 16:12 rodrigondec