-
Notifications
You must be signed in to change notification settings - Fork 401
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
Bug: Revert changes that impacts v3 #5029
Comments
@leandrodamascena, regarding point 1, as far as I can see, code has always been importing Looks like for both points 1 and 2, Pydantic-specific code will need to be under some runtime check depending on each case. For example instead of: if isinstance(res, BaseModel):
return _model_dump(
res,
by_alias=True,
exclude_unset=exclude_unset,
exclude_defaults=exclude_defaults,
exclude_none=exclude_none,
) we could use a duck-typing-"Look Before You Leap" (LBYL) style like: if hasattr(res, "model_dump"):
return _model_dump(
res,
by_alias=True,
exclude_unset=exclude_unset,
exclude_defaults=exclude_defaults,
exclude_none=exclude_none,
) or an arguably preferred (because under the hood, hasattr is actually checking for an AttributeError exception being raised by getattr) "Easier to Ask Forgiveness Than Permission" (EAFP) style like: try:
return _model_dump(
res,
by_alias=True,
exclude_unset=exclude_unset,
exclude_defaults=exclude_defaults,
exclude_none=exclude_none,
)
except AttributeError:
... I'd say it goes on depending on each code that should only optionally work with Pydantic, only if it's available. |
I don't think @ericbn! We are importing this inside the if TYPE_CHECKING:
from pydantic import BaseModel # noqa: F401
CacheKey = Optional[Callable[..., Any]]
IncEx = Union[Set[int], Set[str], Dict[int, Any], Dict[str, Any]]
ModelNameMap = Dict[Union[Type["BaseModel"], Type[Enum]], str]
TypeModelOrEnum = Union[Type["BaseModel"], Type[Enum]]
UnionType = getattr(types, "UnionType", Union) |
Oi @leandrodamascena. Sorry, I now realize there are at least 3 different scenarios and I was not properly distinguishing between them:
TL;DR My last comment above is a mess mixing up independent scenarios where pydantic is being used in different ways. :- ) |
This is completely fine and important because you define exactly how we use Pydantic in different scenarios. I appreciate that.
Wow, this made me search for |
Closing this as completed. |
|
This is now released under 3.0.0 version! |
Expected Behaviour
Some utilities should work without any extra dependency.
Current Behaviour
The V3 branch does not yet have
nox
installed to perform dependency testing and some of our changes have created some unexpected cross-dependency breaking changes.Here is the list of breaking changes detected so far:
1 - We can't import BaseModel outside of
TYPE_CHECKING
because it will force to bring Pydantic at Runtime level even not using data_validation - https://github.com/aws-powertools/powertools-lambda-python/blob/v3/aws_lambda_powertools/event_handler/openapi/types.py#L72 - We can't import ConfigDict because we will force to bring Pydantic event not using data_validation - https://github.com/aws-powertools/powertools-lambda-python/blob/v3/aws_lambda_powertools/event_handler/openapi/constants.py#L1
3 - We need to restore
get_header..
andget_querystring..
functions removed by this PR - https://github.com/aws-powertools/powertools-lambda-python/pull/4606/files4 - We need to add more e2e tests.
Code snippet
Possible Solution
No response
Steps to Reproduce
Install and run
Powertools for AWS Lambda (Python) version
v3
AWS Lambda function runtime
3.11
Packaging format used
PyPi
Debugging logs
No response
The text was updated successfully, but these errors were encountered: