Skip to content

Conversation

@mgeaghan
Copy link

I've added a new screen to capture default process resource requirements. Nothing prints to the final config file just yet but the data is captured within the TEMPLATE_CONFIG object.

In testing I found that the input field validation wasn't working correctly. I tracked it down to how the pydantic context object was being used. When editing a text input field, the utils.ValidateConfig class creates a brand new ConfigsCreateConfig object with just that field's data, using utils.init_context() to set the value of the variable _init_context_var:

with init_context({"is_nfcore": NFCORE_CONFIG_GLOBAL, "is_infrastructure": CONFIG_ISINFRASTRUCTURE_GLOBAL}):
    ConfigsCreateConfig(**{f"{self.key}": value})
    return self.success()

That context variable used to then conditionally assess the validity of the field:

@field_validator("config_pipeline_path")
@classmethod
def path_valid(cls, v: str, info: ValidationInfo) -> str:
    """Check that a path is valid."""
    context = info.context
    if context and (not context["is_infrastructure"] and not context["is_nfcore"]):
        if v.strip() == "":
            raise ValueError("Cannot be left empty.")
        if not Path(v).is_dir():
            raise ValueError("Must be a valid path.")
    return v

The problem is that init_context() resets the value of _init_context_var after it has been used, so when the user clicks a button to progress to the next screen, it will progress even if some fields are invalid. Because of this, I think this has gone unnoticed, since the fields still highlight red and display the error message, but only one or two of these actually stopped the progression through the app.

I've updated how the config gets updated when the user clicks 'Next' on the basic details screen so that we wrap the creation of the ConfigsCreateConfig object within a with init_context() call, similar to above:

try:
    with init_context({"is_nfcore": self.parent.NFCORE_CONFIG, "is_infrastructure": self.parent.CONFIG_TYPE == "infrastructure"}):
        self.parent.TEMPLATE_CONFIG = ConfigsCreateConfig(**config)

I'm not sure if this is the best way to approach this, so I thought I'd open this small PR to discuss.

I also updated a few of the @field_validator methods to properly reflect which fields are hidden and shown within the app.

PR checklist

  • This comment contains a description of changes (with reason)
  • CHANGELOG.md is updated
  • If you've fixed a bug or added code that should be tested, add tests!
  • Documentation in docs is updated

@mgeaghan mgeaghan requested a review from mirpedrol December 18, 2025 03:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant