Skip to content

Commit

Permalink
Prevent select box choices filtered improperly when no query applied
Browse files Browse the repository at this point in the history
Refs GH-172
  • Loading branch information
bchopson authored and guruofgentoo committed Dec 2, 2022
1 parent 97244de commit aef1cf0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion keg_elements/forms/__init__.py
Expand Up @@ -409,7 +409,7 @@ def filter_query(self, query):
# Having an existing value should filter the query.
if self.data is not None:
data_filter = self.get_data_filter()
if data_filter is not None:
if data_filter is not None and filter_terms:
filter_terms.append(data_filter)

# Apply filter terms with or_, or directly, depending on length.
Expand Down
8 changes: 8 additions & 0 deletions keg_elements/tests/test_forms/test_form.py
Expand Up @@ -1123,6 +1123,14 @@ def test_choices_included(self):
obj=related_thing)
assert form.thing_id.choice_values == ['', thing2.id, thing1.id]

def test_choices_data_filter_not_applied_incorrectly(self):
thing1 = ents.Thing.testing_create(name='foo', color='blue')
thing2 = ents.Thing.testing_create(name='bar', color='red')
thing3 = ents.Thing.testing_create(name='baz', color='purple')
related_thing = ents.RelatedThing.testing_create(thing=thing1)
form = self.create_custom_form({'query_filter': None}, obj=related_thing)
assert form.thing_id.choice_values == ['', thing2.id, thing3.id, thing1.id]


class TestCollectionRelationship(RelationshipMixin):
"""Test field that corresponds to a SA collection."""
Expand Down

0 comments on commit aef1cf0

Please sign in to comment.