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

Several tests fail with Pydantic 1.10.15 (latest 1.x) #3600

Closed
musicinmybrain opened this issue May 25, 2024 · 6 comments
Closed

Several tests fail with Pydantic 1.10.15 (latest 1.x) #3600

musicinmybrain opened this issue May 25, 2024 · 6 comments
Assignees
Labels
stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at.

Comments

@musicinmybrain
Copy link
Contributor

Description

Pydantic 1.10.15 aliases the pydantic namespace as pydantic.v1 as a forward-compatibility feature. This seems to interact badly with several

Steps to reproduce

$ gh repo clone aws/serverless-application-model
$ cd serverless-application-model
$ python3 -m venv _e
$ . _e/bin/activate
(_e) $ pip install -e .[dev]
(_e) $ pip install pydantic==1.10.15
(_e) $ make test

Observed result

=========================================================================================== short test summary info ============================================================================================
FAILED tests/model/test_resource_validator.py::TestResourceValidatorFailure::test_connector_with_empty_properties - AttributeError: module 'pydantic.v1' has no attribute 'error_wrappers'
FAILED tests/model/test_resource_validator.py::TestResourceValidatorFailure::test_connector_with_invalid_permission - AttributeError: module 'pydantic.v1' has no attribute 'error_wrappers'
FAILED tests/model/test_resource_validator.py::TestResourceValidatorFailure::test_connector_with_invalid_permission_type - AttributeError: module 'pydantic.v1' has no attribute 'error_wrappers'
FAILED tests/model/test_resource_validator.py::TestResourceValidatorFailure::test_connector_without_source - AttributeError: module 'pydantic.v1' has no attribute 'error_wrappers'
FAILED tests/translator/test_translator.py::test_transform_invalid_document[error_graphqlapi] - AttributeError: module 'pydantic.v1' has no attribute 'error_wrappers'
============================================================================= 5 failed, 3967 passed, 5 rerun in 104.48s (0:01:44) =============================================================================

Expected result

(_e) $ pip install pydantic==1.10.14
(_e) $ make test
======================================================================================= 3972 passed in 103.63s (0:01:43) =======================================================================================

Additional environment details

  1. OS: Fedora 39 x86_64
  2. If using the SAM CLI, sam --version: N/A
  3. AWS region: N/A
@musicinmybrain musicinmybrain added the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label May 25, 2024
@musicinmybrain
Copy link
Contributor Author

In Pydantic 1.10.14, from pydantic import v1 as pydantic raises an ImportError in

try:
from pydantic import v1 as pydantic
except ImportError:
# Unfortunately mypy cannot handle this try/expect pattern, and "type: ignore"
# is the simplest work-around. See: https://github.com/python/mypy/issues/1153
import pydantic # type: ignore

and import pydantic is used.

In Pydantic 1.10.14, from pydantic import v1 as pydantic succeeds, but pydantic.v1.error_wrappers is not present, only pydantic.error_wrappers; therefore, samtranslator.compat.pydantic.error_wrappers is not present.

Related: https://github.com/pydantic/pydantic/blob/5476a758c8ac59887dbfa3aa1c3481d0a0e20837/pydantic/v1.py#L5-L6

musicinmybrain added a commit to musicinmybrain/serverless-application-model that referenced this issue May 25, 2024
@musicinmybrain
Copy link
Contributor Author

I’ll try to offer a PR for this later today.

@musicinmybrain
Copy link
Contributor Author

I’ll try to offer a PR for this later today.

I am actually not sure what the correct approach is here. Using pydantic.ValidationError in the except …: isn’t right (on Pydantic v2, it is pydantic_core._pydantic_core.ValidationError, which has no direct inheritance relationship with pydantic.v1.error_wrappers.ValidationError).

It seems like it might be a bug that pydantic.v1.error_wrappers isn’t present in Pydantic 1.10.15, and that this might be the same as pydantic/pydantic#9357, but I don’t have enough Pydantic experience to state that confidently.

@shikha372 shikha372 self-assigned this Jun 10, 2024
@shikha372
Copy link
Contributor

shikha372 commented Jun 10, 2024

Was able to reproduce this issue on local

Issue opened with pydantic team for import error
pydantic/pydantic#9625

@shikha372
Copy link
Contributor

shikha372 commented Jun 10, 2024

Thanks @musicinmybrain for highlighting this issue. We've opened a bug at pydantic end to check this, meanwhile added this to list of expected exception at SAM end in PR#3611 . Let us know if you still have any questions regarding this.

Copy link
Contributor

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at.
Projects
None yet
Development

No branches or pull requests

2 participants