From 70ed2dc78c8c0f78193f92fcb684be6eea2c3595 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Mon, 27 Jan 2025 15:55:07 -0600 Subject: [PATCH] fix: do not auto-create grid filters for uuid columns --- src/wuttaweb/grids/base.py | 25 ++++++++++++++++++------- tests/grids/test_base.py | 3 +++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/wuttaweb/grids/base.py b/src/wuttaweb/grids/base.py index e69d876..44c2170 100644 --- a/src/wuttaweb/grids/base.py +++ b/src/wuttaweb/grids/base.py @@ -41,6 +41,7 @@ from webhelpers2.html import HTML from wuttaweb.db import Session from wuttaweb.util import FieldList, get_model_fields, make_json_safe from wuttjamaican.util import UNSPECIFIED +from wuttjamaican.db.util import UUID from wuttaweb.grids.filters import default_sqlalchemy_filters, VerbNotSupported @@ -1136,14 +1137,15 @@ class Grid: def make_backend_filters(self, filters=None): """ - Make backend filters for all columns in the grid. + Make "automatic" backend filters for the grid. This is called by the constructor, if :attr:`filterable` is true. - For each column in the grid, this checks the provided - ``filters`` and if the column is not yet in there, will call - :meth:`make_filter()` to add it. + For each "column" in the model class, this will call + :meth:`make_filter()` to add an automatic filter. However it + first checks the provided ``filters`` and will not override + any of those. .. note:: @@ -1181,9 +1183,18 @@ class Grid: inspector = sa.inspect(self.model_class) for prop in inspector.column_attrs: - if prop.key not in filters: - attr = getattr(self.model_class, prop.key) - filters[prop.key] = self.make_filter(attr) + + # do not overwrite existing filters + if prop.key in filters: + continue + + # do not create filter for UUID field + if (len(prop.columns) == 1 + and isinstance(prop.columns[0].type, UUID)): + continue + + attr = getattr(self.model_class, prop.key) + filters[prop.key] = self.make_filter(attr) return filters diff --git a/tests/grids/test_base.py b/tests/grids/test_base.py index 8a8b14e..0184c0c 100644 --- a/tests/grids/test_base.py +++ b/tests/grids/test_base.py @@ -1021,6 +1021,9 @@ class TestGrid(WebTestCase): self.assertIn('active', filters) # nb. relationship not included by default self.assertNotIn('person', filters) + # nb. uuid fields not included by default + self.assertNotIn('uuid', filters) + self.assertNotIn('person_uuid', filters) def test_make_filter(self): model = self.app.model