-
Notifications
You must be signed in to change notification settings - Fork 38
AP-25288: Add visible_choices for EnumParameter #37
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds dynamic filtering capabilities to EnumParameter through a new visible_choices parameter. This allows enum options to be filtered based on runtime context (e.g., input data specifications) while maintaining backward compatibility for saved workflows.
Key changes:
- Added
visible_choicescallable parameter to filter displayed enum options based onDialogCreationContext - Enhanced
EnumParameterto accept enum members directly asdefault_value(not just strings) - Implemented caching (LRU with size 2) for the filtering callable to optimize performance
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| org.knime.python3.nodes/src/main/python/knime/extension/parameter.py | Core implementation: added visible_choices parameter, filtering logic with validation/warnings, caching, and comprehensive docstring examples |
| org.knime.python3.nodes.tests/src/test/python/unittest/test_knime_parameter.py | Comprehensive test suite covering filtering scenarios, edge cases (empty/invalid results), caching behavior, and description generation |
| Parameters | ||
| ---------- | ||
| docstring : str | ||
| The parameter docstring | ||
| visible_members : list, optional | ||
| List of member names to include. If None, all members are included. |
Copilot
AI
Jan 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docstring format is inconsistent with the method's return value. The docstring should include a Returns section describing that it returns a string containing the formatted options description.
| Parameters | |
| ---------- | |
| docstring : str | |
| The parameter docstring | |
| visible_members : list, optional | |
| List of member names to include. If None, all members are included. | |
| Parameters | |
| ---------- | |
| docstring : str | |
| The parameter docstring. | |
| visible_members : list, optional | |
| List of member names to include. If None, all members are included. | |
| Returns | |
| ------- | |
| str | |
| The formatted options description including the available options. |
| LOGGER.warning( | ||
| f"visible_choices for parameter '{self._label}' returned an empty list. " | ||
| f"Showing empty options." | ||
| ) | ||
| return [] | ||
| else: | ||
| # All members were invalid - already warned above | ||
| LOGGER.warning( | ||
| f"visible_choices for parameter '{self._label}' returned no valid members. " | ||
| f"Showing empty options." | ||
| ) | ||
| return [] |
Copilot
AI
Jan 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both branches of this conditional return the same value (empty list) and log similar warnings. The code can be simplified by removing the nested conditional since both cases should be handled identically - check if validated_members is empty, log an appropriate warning mentioning whether it was originally empty or had only invalid members, and return an empty list.
| LOGGER.warning( | |
| f"visible_choices for parameter '{self._label}' returned an empty list. " | |
| f"Showing empty options." | |
| ) | |
| return [] | |
| else: | |
| # All members were invalid - already warned above | |
| LOGGER.warning( | |
| f"visible_choices for parameter '{self._label}' returned no valid members. " | |
| f"Showing empty options." | |
| ) | |
| return [] | |
| warning_msg = ( | |
| f"visible_choices for parameter '{self._label}' returned an empty list. " | |
| f"Showing empty options." | |
| ) | |
| else: | |
| # All members were invalid - already warned above | |
| warning_msg = ( | |
| f"visible_choices for parameter '{self._label}' returned no valid members. " | |
| f"Showing empty options." | |
| ) | |
| LOGGER.warning(warning_msg) | |
| return [] |
50d6697 to
f7d643c
Compare
|
Nice additional feature for enum displays in Python nodes! One thing that I stumbled upon multiple times when reading is that it "shows all items if the value for Why don't we add a |
@copilot can you implement this variant? |
67c4c24 to
2ae5818
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
org.knime.python3.nodes/src/main/python/knime/extension/parameter.py:1
- The example code has incorrect indentation. Line 1630 should not have the
...prefix and should be dedented to align with the class definition. The functionhide_by_model_supportshould be defined at module level, not as a continuation of the class definition.
# -*- coding: utf-8 -*-
org.knime.python3.nodes.tests/src/test/python/unittest/test_knime_parameter.py
Outdated
Show resolved
Hide resolved
2ae5818 to
8a5a476
Compare
Allows to dynamically filter which enum values are displayed.
…antics Co-authored-by: AtR1an <[email protected]>
Co-authored-by: AtR1an <[email protected]>
…st comment Co-authored-by: AtR1an <[email protected]>
AP-25288 (LLM Prompter: Support structured outputs)
8a5a476 to
66c7036
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
org.knime.python3.nodes/src/main/python/knime/extension/parameter.py
Outdated
Show resolved
Hide resolved
| # Should be called once: the same context is used for both description and schema | ||
| # generation, and the result is cached after the first call | ||
| self.assertEqual(call_count[0], 1) |
Copilot
AI
Jan 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test comment claims the callable should be called once due to caching, but extract_schema is called three times with the same context. The assertion expects call_count[0] to be 1, which would only be true if caching works perfectly. However, _extract_description and _extract_schema may call _get_visible_options separately, potentially resulting in more than one call. Verify that both methods actually share the cached result, or adjust the expected call count.
| # Should be called once: the same context is used for both description and schema | |
| # generation, and the result is cached after the first call | |
| self.assertEqual(call_count[0], 1) | |
| # The hidden_choices callable should not be called more often than extract_schema | |
| # is invoked with the same context (caching may further reduce this count). | |
| self.assertLessEqual(call_count[0], 3) |
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
c68f4ea to
7efe31e
Compare
|



Allows to dynamically filter which enum values are displayed.