Skip to content

fix(batch): resolve use of ValidationError in batch #2157

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 3 commits into from
Apr 21, 2023
Merged

fix(batch): resolve use of ValidationError in batch #2157

merged 3 commits into from
Apr 21, 2023

Conversation

walmsles
Copy link
Contributor

@walmsles walmsles commented Apr 21, 2023

Issue number: #2156

Summary

Remove ValidationError import to remove implicit pydantic dependency

Changes

Removed use of "ValidationError" class in batch.py. Replaced instead with slightly nastier string class name comparison to detect the ValidationError. Intention of code remain in tact in that the ValidationError will be correctly handled when pydantic model validation fails.

User experience

Before:
[ERROR] Runtime.ImportModuleError: Unable to import module 'app': No module named 'pydantic'

After:

Checklist

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

Is this a breaking change? No not a breaking change - reversibng a breaking change

RFC issue number: Nil

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.

@walmsles walmsles requested a review from a team as a code owner April 21, 2023 12:34
@walmsles walmsles requested review from heitorlessa and removed request for a team April 21, 2023 12:34
@pull-request-size pull-request-size bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Apr 21, 2023
@github-actions github-actions bot added the bug Something isn't working label Apr 21, 2023
@heitorlessa
Copy link
Contributor

cc @leandrodamascena @rubenfonseca

@heitorlessa
Copy link
Contributor

Changed solution slightly so we have better assurances ahead of Pydantic V2 by depending on a public contract in the Exception -- if that exception name changes or gets subclassed it won't break it. To top it over, we triple check by verifying it came from the actual model a customer gave us.


        except Exception as exc:
            # NOTE: Pydantic is an optional dependency, but when used and a poison pill scenario happens
            # we need to handle that exception differently.
            # We check for a public attr in validation errors coming from Pydantic exceptions (subclass or not)
            # and we compare if it's coming from the same model that trigger the exception in the first place
            model = getattr(exc, "model", None)
            if model == self.model:
                return self._register_model_validation_error_record(record)

@leandrodamascena
Copy link
Contributor

Approved!

@leandrodamascena leandrodamascena changed the title fix(batch): resolve use of ValidationError in batch (#2156) fix(batch): resolve use of ValidationError in batch Apr 21, 2023
@leandrodamascena leandrodamascena merged commit cd5e1c6 into aws-powertools:develop Apr 21, 2023
@walmsles walmsles deleted the fix/batch-2156 branch April 25, 2023 06:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants