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

DirectoryPathMustExist and friends are not compatible with Pydantic 2.8.0 #498

Open
joanise opened this issue Jul 3, 2024 · 3 comments
Open
Labels
bug Something isn't working help wanted Extra attention is needed
Milestone

Comments

@joanise
Copy link
Member

joanise commented Jul 3, 2024

In a fresh environment, where the default pydantic is now 2.8.0, we get 11 unit testing errors from test_configs.py and test_utils.py.
If I force <2.8.0, the errors disappear. The result atm is that CI is broken.

Quick hack

I'm going to set pydantic[email]>=2.4.2,<2.8 in requirements.txt, so CI can pass again for now.

Steps to reproduce

./make-everyvoice-env -n EV-new
conda activate EV-new
pip install 'pydantic[email]==2.8.0'  # only required once I lock to <2.8
python -m unittest everyvoice.tests.test_utils everyvoice.tests.test_configs
# see 11 failures
pip install 'pydantic[email]<2.8.0'
rmdir test_using_a_directory_with_context/ logs_and_checkpoints/
python -m unittest everyvoice.tests.test_utils everyvoice.tests.test_configs
# see all tests pass

Desired fix

Make the code compatible with 2.8.0.

Full error log with 2.8.0

======================================================================
FAIL: test_using_a_directory_with_context (everyvoice.tests.test_utils.DirectoryPathMustExistTest)
Verifies that directory_path_must_exist(), when using a context,
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/gpfs/fs3c/nrc/ict/portage/u/joa125/EveryVoice/EveryVoice/everyvoice/tests/test_utils.py", line 232, in test_using_a_directory_with_context
    self.assertTrue((root_dir / directory).exists())
AssertionError: False is not true

======================================================================
FAIL: test_using_a_directory_with_context (everyvoice.tests.test_utils.PathIsADirectoryTest)
Verifies that PathIsADirectory detects that the argument is a directory
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/gpfs/fs3c/nrc/ict/portage/u/joa125/EveryVoice/EveryVoice/everyvoice/tests/test_utils.py", line 99, in test_using_a_directory_with_context
    PathIsADirectory(path=directory)
  File "/gpfs/fs3c/nrc/ict/portage/u/joa125/EveryVoice/EveryVoice/everyvoice/tests/test_utils.py", line 72, in __init__
    __pydantic_self__.__pydantic_validator__.validate_python(
pydantic_core._pydantic_core.ValidationError: 1 validation error for PathIsADirectory
path
  Value error, hierarchy is not a directory [type=value_error, input_value=PosixPath('hierarchy'), input_type=PosixPath]
    For further information visit https://errors.pydantic.dev/2.8/v/value_error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/gpfs/fs3c/nrc/ict/portage/u/joa125/EveryVoice/EveryVoice/everyvoice/tests/test_utils.py", line 101, in test_using_a_directory_with_context
    self.fail("Failed to detect that the argument is a directory")
AssertionError: Failed to detect that the argument is a directory

======================================================================
FAIL: test_using_a_file_with_context (everyvoice.tests.test_utils.PathIsADirectoryTest)
Verifies that PathIsADirectory detects that the argument is a file when
----------------------------------------------------------------------
pydantic_core._pydantic_core.ValidationError: 1 validation error for PathIsADirectory
path
  Value error, test_utils.py is not a directory [type=value_error, input_value='test_utils.py', input_type=str]
    For further information visit https://errors.pydantic.dev/2.8/v/value_error

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/gpfs/fs3c/nrc/ict/portage/u/joa125/EveryVoice/EveryVoice/everyvoice/tests/test_utils.py", line 109, in test_using_a_file_with_context
    with self.assertRaisesRegex(
AssertionError: "/gpfs/fs3c/nrc/ict/portage/u/joa125/EveryVoice/EveryVoice/everyvoice/tests/test_utils.py is not a directory" does not match "1 validation error for PathIsADirectory
path
  Value error, test_utils.py is not a directory [type=value_error, input_value='test_utils.py', input_type=str]
    For further information visit https://errors.pydantic.dev/2.8/v/value_error"

======================================================================
FAIL: test_with_context (everyvoice.tests.test_utils.RelativePathToAbsoluteTest)
When provided with a context, the path should be absolute.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/gpfs/fs3c/nrc/ict/portage/u/joa125/EveryVoice/EveryVoice/everyvoice/tests/test_utils.py", line 196, in test_with_context
    self.assertTrue(dir.path.is_absolute())
AssertionError: False is not true

======================================================================
FAIL: test_config_save_dirs (everyvoice.tests.test_configs.ConfigTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/gpfs/fs3c/nrc/ict/portage/u/joa125/EveryVoice/EveryVoice/everyvoice/tests/test_configs.py", line 101, in test_config_save_dirs
    self.assertTrue((tempdir / preprocessing_config.save_dir).exists())
AssertionError: False is not true

======================================================================
FAIL: test_absolute_path (everyvoice.tests.test_configs.LoadConfigTest)
Load a config that has absolute paths.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/gpfs/fs3c/nrc/ict/portage/u/joa125/EveryVoice/EveryVoice/everyvoice/tests/test_configs.py", line 538, in test_absolute_path
    self.validate_config_path(config.training.logger.save_dir)
  File "/gpfs/fs3c/nrc/ict/portage/u/joa125/EveryVoice/EveryVoice/everyvoice/tests/test_configs.py", line 363, in validate_config_path
    self.assertTrue(path.is_absolute(), msg=path)
AssertionError: False is not true : logs_and_checkpoints

======================================================================
FAIL: test_aligner_config (everyvoice.tests.test_configs.LoadConfigTest)
Create a AlignerConfig which pydantic will validate for us.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/gpfs/fs3c/nrc/ict/portage/u/joa125/EveryVoice/EveryVoice/everyvoice/tests/test_configs.py", line 385, in test_aligner_config
    self.validate_config_path(config.training.logger.save_dir)
  File "/gpfs/fs3c/nrc/ict/portage/u/joa125/EveryVoice/EveryVoice/everyvoice/tests/test_configs.py", line 363, in validate_config_path
    self.assertTrue(path.is_absolute(), msg=path)
AssertionError: False is not true : ../logs_and_checkpoints

======================================================================
FAIL: test_everyvoice_config (everyvoice.tests.test_configs.LoadConfigTest)
Create a EveryVoiceConfig which pydantic will validate for us.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/gpfs/fs3c/nrc/ict/portage/u/joa125/EveryVoice/EveryVoice/everyvoice/tests/test_configs.py", line 479, in test_everyvoice_config
    self.validate_config_path(config.training.logger.save_dir)
  File "/gpfs/fs3c/nrc/ict/portage/u/joa125/EveryVoice/EveryVoice/everyvoice/tests/test_configs.py", line 363, in validate_config_path
    self.assertTrue(path.is_absolute(), msg=path)
AssertionError: False is not true : ../logs_and_checkpoints

======================================================================
FAIL: test_feature_prediction_config (everyvoice.tests.test_configs.LoadConfigTest)
Create a FeaturePredictionConfig which pydantic will validate for us.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/gpfs/fs3c/nrc/ict/portage/u/joa125/EveryVoice/EveryVoice/everyvoice/tests/test_configs.py", line 427, in test_feature_prediction_config
    self.validate_config_path(config.training.logger.save_dir)
  File "/gpfs/fs3c/nrc/ict/portage/u/joa125/EveryVoice/EveryVoice/everyvoice/tests/test_configs.py", line 363, in validate_config_path
    self.assertTrue(path.is_absolute(), msg=path)
AssertionError: False is not true : ../logs_and_checkpoints

======================================================================
FAIL: test_preprocessing_config (everyvoice.tests.test_configs.LoadConfigTest)
Create a PreprocessingConfig which pydantic will validate for us.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/gpfs/fs3c/nrc/ict/portage/u/joa125/EveryVoice/EveryVoice/everyvoice/tests/test_configs.py", line 403, in test_preprocessing_config
    self.validate_config_path(config.save_dir)
  File "/gpfs/fs3c/nrc/ict/portage/u/joa125/EveryVoice/EveryVoice/everyvoice/tests/test_configs.py", line 363, in validate_config_path
    self.assertTrue(path.is_absolute(), msg=path)
AssertionError: False is not true : ../preprocessed

======================================================================
FAIL: test_vocoder_config (everyvoice.tests.test_configs.LoadConfigTest)
Create a VocoderConfig which pydantic will validate for us.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/gpfs/fs3c/nrc/ict/portage/u/joa125/EveryVoice/EveryVoice/everyvoice/tests/test_configs.py", line 448, in test_vocoder_config
    self.validate_config_path(config.training.logger.save_dir)
  File "/gpfs/fs3c/nrc/ict/portage/u/joa125/EveryVoice/EveryVoice/everyvoice/tests/test_configs.py", line 363, in validate_config_path
    self.assertTrue(path.is_absolute(), msg=path)
AssertionError: False is not true : ../logs_and_checkpoints

----------------------------------------------------------------------
Ran 48 tests in 1.245s

FAILED (failures=11)
@joanise joanise added bug Something isn't working help wanted Extra attention is needed labels Jul 3, 2024
@joanise joanise added this to the beta milestone Jul 3, 2024
@joanise
Copy link
Member Author

joanise commented Jul 3, 2024

@SamuelLarkin not urgent, since #499 provides a work-around for now, but when you have time can you look at this?

@joanise
Copy link
Member Author

joanise commented Sep 9, 2024

@roedoejet I would bump this to milestone 1.0: we don't need to fix this until we want/need to upgrade to a newer Pydantic.

@joanise joanise modified the milestones: beta, 1.0 Sep 9, 2024
@roedoejet
Copy link
Member

@roedoejet I would bump this to milestone 1.0: we don't need to fix this until we want/need to upgrade to a newer Pydantic.

good idea!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants