Skip to content

fix(event_handler): lazy load Pydantic to improve cold start #3397

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

Merged
merged 6 commits into from
Nov 22, 2023

Conversation

rubenfonseca
Copy link
Contributor

@rubenfonseca rubenfonseca commented Nov 22, 2023

Issue number: #3370

Summary

Changes

Please provide a summary of what's being changed

This PR fixes the problem where Pydantic was being loaded when using the event handler, even though no data validation was being used.

User experience

Please share what the user experience looks like before and after this change

BEFORE

image

AFTER

image

Checklist

If your change doesn't seem to apply, please leave them unchecked.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 22, 2023
@rubenfonseca rubenfonseca force-pushed the rf/fix-openapi-imports branch from cccd768 to 84dcceb Compare November 22, 2023 16:31
@pull-request-size pull-request-size bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 22, 2023
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@rubenfonseca rubenfonseca added this to the OpenAPI in Event Handler milestone Nov 22, 2023
@rubenfonseca rubenfonseca marked this pull request as ready for review November 22, 2023 16:42
@rubenfonseca rubenfonseca requested review from a team and heitorlessa November 22, 2023 16:42
@heitorlessa
Copy link
Contributor

for my own understanding in the future... the reason this "lazy" works is that:

  • Event Handler entry point is importing openapi/types.py
  • We were importing Pydantic to confirm it was present at the global scope
  • This change moves the try/catch to a separate module which is not requested by openapi/types.py
  • When enable_validation=True is used, we effectively import the rest which will import the new module that imports Pydantic to confirm is installed or not
image image

@heitorlessa heitorlessa added the bug Something isn't working label Nov 22, 2023
@heitorlessa heitorlessa merged commit 0cc687a into develop Nov 22, 2023
@heitorlessa heitorlessa deleted the rf/fix-openapi-imports branch November 22, 2023 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working event_handlers size/S Denotes a PR that changes 10-29 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Pydantic is being imported when using Event Handler without validation
2 participants