Skip to content
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

With use_strict enabled, configured output files fail Pydantic validation #793

Closed
program-- opened this issue Jul 2, 2024 · 0 comments
Closed

Comments

@program--
Copy link
Contributor

program-- commented Jul 2, 2024

Current Behavior

When chanobs_filepath is defined in a t-route configuration file, executing Config.with_strict_mode(...) results in a Pydantic validation error.

Expected Behavior

Using with_strict_mode shouldn't raise a file not found validation error on output files.

Details

In NOAA-OWP/ngen our t-route integration tests have started failing due to the Chanobs.nc file not existing. My understanding is that this is an output file, so it shouldn't necessarily exist until after t-route has executed.

  • Backtracing the error, it starts with strict mode being enabled for config parsing with d443337.
  • Looking in troute-config, chanobs_filepath has type FilePath
    chanobs_filepath: Optional[FilePath] = None

    and FilePath is defined as
    class FilePath(PydanticFilePath):
    """
    Coerce into a `pathlib.Path` type. If strict mode is enabled (see _utils.use_strict), will raise
    if file does not exist.
    """
    @classmethod
    def __get_validators__(cls) -> "CallableGenerator":
    yield cls.validate
    @classmethod
    def validate(cls, value: Path) -> Path:
    if strict_set():
    for validator in PydanticFilePath.__get_validators__():
    value = validator(value)
    return value
    else:
    return Path(value)

I think a slight semantic change is necessary, i.e. something like InputFilePath and OutputFilePath, where InputFilePath parameters are validated for existence in the same way that FilePath is, and OutputFilePath are validated only for write permissions in the parent directory but not existence.

Though, it's entirely possible I'm misunderstanding something, so please let me know if I am! 🙂

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

No branches or pull requests

1 participant