Fix bugs in json_utils.py: logic errors, unpacking crashes, and mangl…#37589
Fix bugs in json_utils.py: logic errors, unpacking crashes, and mangl…#37589atheendre130505 wants to merge 2 commits intoapache:masterfrom
Conversation
…ed error messages
Summary of ChangesHello @atheendre130505, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses several critical bugs within Apache Beam's json_utils.py module, specifically impacting the validation and error reporting for object-type schemas. The changes improve the robustness of schema validation, prevent runtime crashes during dictionary iteration, and ensure that error messages are correctly formatted and informative, thereby enhancing the reliability of the YAML JSON utility. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment |
34e2948 to
e3c27bd
Compare
|
Run Python PreCommit 3.10 |
Fix json_utils.py object validation logic and mangled error messages
This PR addresses critical bugs in Apache Beam's YAML JSON utility that led to silent validation passes or internal crashes when handling object-type schemas.
Changes: Corrected Object Validation: Fixed logic in _validate_compatible where weak_schema == 'object' was always false (comparing dict to string). It now correctly checks weak_schema['type'] == 'object'.
Fixed Iteration Crash: Added .items() to dictionary iteration in _validate_compatible to prevent ValueError: not enough values to unpack. Restored F-Strings: Added missing f prefixes to multiple ValueError and TypeError calls, ensuring error messages like Expected object type, got {json_type} correctly interpolate variables.
Fixed Formatting Bug: Corrected a ValueError in _validate_compatible
where a boolean expression was passed to a format string expecting the type names.
Added Regression Tests: Updated json_utils_test.py with tests verifying that incompatible object schemas are caught and that error messages are properly formatted.
unit tests implemented.
fixes #37576