Add Custom Validation for User-Configured Templates#21155
Add Custom Validation for User-Configured Templates#21155jmchilton merged 10 commits intogalaxyproject:devfrom
Conversation
|
These don't use the pre-existing tool_util validators but the schema for declaring them looks compatible. It is intention that the schema is the same I assume? I wish that code had been reusable but if the schema is the same and there is test coverage I think this is fine to not reuse that stuff. |
|
Good point! I was not aware of the pre-existing tool_util validators, but I guess Claude tried to keep consistency with them when suggesting the schema. |
|
The existing tool_util validators are now reused. Thanks again for catching that! |
3ee6558 to
413c579
Compare
|
It might be the case that galaxy-util is Python 3.7 compatible and galaxy-tool-util-models isn't - or you maybe need to have galaxy-util depend on galaxy-tool-util-models. Not sure but I could imagine both being a problem. |
|
Oops! I completely missed those test failures because I thought they were part of the known package test failures and didn't even check them 😅 Thanks for noticing! I will take a look 👍 |
Introduces a flexible validator system for template variables, enabling regex, length, and range checks with customizable messages.
Introduces a mechanism for attaching and evaluating custom validators (such as regex patterns) to template variables in form handling logic. Enhances client-side validation to catch invalid input earlier and provide immediate feedback, improving user experience and reducing unnecessary server requests.
Introduces regex-based validators to prevent leading/trailing whitespace and trailing slashes in bucket names, reducing misconfiguration risks and improving user input reliability.
Moves Sequence import to typing to avoid "'ABCMeta' object is not subscriptable" issues. Co-authored-by: Nicola Soranzo <nicola.soranzo@earlham.ac.uk>
413c579 to
0f8aa5f
Compare
|
Looks like @nsoranzo suggestion worked! Only unrelated test failures now :) |
| RequestParameterInvalidException, | ||
| RequestParameterMissingException, | ||
| ) | ||
| from galaxy.tool_util_models.parameter_validators import AnySafeValidatorModel |
There was a problem hiding this comment.
This makes the galaxy-util package dependent on galaxy-tool-util-models, which wasn't the case before.
galaxy-util 26.0.0 is currently broken because it doesn't specify this dependency, see e.g.
We have 3 options:
- Formalise this new dependency by adding it to
packages/util/setup.cfg - Move the import under
if TYPE_CHECKING:(a good idea any way) - Refactor the code (which seems complicated)
@jmchilton Any preference?
There was a problem hiding this comment.
I the abstract I don't think galaxy-util should depend on galaxy-tool-util-models - so I like the TYPE_CHECKING import here with the long term goal of pushing this stuff up and out of galaxy.util - maybe into galaxy-files or galaxy-data or something new like galaxy-config-templates or something like that.
There was a problem hiding this comment.
I've tried to use the TYPE_CHECKING approach here, but it doesn't work because AnySafeValidatorModel is used to annotate a Pydantic model, so it needs to be defined at runtime.
Therefore I've opted to add a dependency on galaxy-tool-util-models to the config-template extra of galaxy-util, which seems acceptable?
I've add the fix to #22445 , with a bunch of other fixes to packaging.
Closes #20904
This PR adds custom validation to template variables in file source and object store templates, enforcing input constraints with clear error messages.
Features
Three validator types:
regex: Pattern matching with optional negationlength: String length bounds (min/max)range: Numeric value bounds (min/max)Key characteristics:
Example Usage (included in
lib/galaxy/files/templates/examples/production_s3fs.yml)This prevents common configuration mistakes and improves the user experience when setting up custom storage connections.
How to test the changes?
License