fix: Proper parsing of GCP credentials JSON#10828
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughAdds four fallback strategies to Google Drive service-account JSON parsing in SaveToFile and adds async tests covering control characters, whitespace, and double-encoded credential formats. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Suggested labels
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (6 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. ❌ Your project status has failed because the head coverage (39.99%) is below the target coverage (60.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #10828 +/- ##
==========================================
+ Coverage 32.53% 32.55% +0.01%
==========================================
Files 1370 1370
Lines 63514 63514
Branches 9391 9391
==========================================
+ Hits 20665 20675 +10
+ Misses 41810 41800 -10
Partials 1039 1039
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
@erichare The codec error persists:
Error building Component Write File:
'charmap' codec can't encode characters in position 20439-20442: character maps to <undefined>
When trying to save a plain text file, I encountered a new error:
Error building Component Write File:
Unable to access Google Drive folder '1FCkhUiNYiaBJrc979ovLWLnPaaCP-tAB'. Error: <HttpError 404 when requesting https://www.googleapis.com/drive/v3/files/1FCkhUiNYiaBJrc979ovLWLnPaaCP-tAB?fields=id%2Cname&alt=json returned "File not found: 1FCkhUiNYiaBJrc979ovLWLnPaaCP-tAB." Details: "[{'message': 'File not found: 1FCkhUiNYiaBJrc979ovLWLnPaaCP-tAB.', 'domain': 'global', 'reason': 'notFound', 'location': 'fileId', 'locationType': 'parameter'}]">. Please ensure: 1) The folder ID is correct, 2) The folder exists, 3) The service account has been granted access to this folder.
I tested the same files with a specific component for Google Drive and it worked correctly, indicating that there is no problem with the key and/or the folder.
Component I used for comparison: https://github.com/Empreiteiro/langflow-factory/blob/master/components/google/drive/google_drive_write.py
Empreiteiro
left a comment
There was a problem hiding this comment.
After the new revisions, the functions are working as expected! LGTM!
Fixes parsing of Write File Component with GCP JSON credentials.
This pull request introduces robust improvements to the Google Drive credential parsing logic and adds new unit tests to ensure reliability when handling Google Cloud service account JSON keys, especially those containing control characters or formatting irregularities. These changes address a bug where pasted GCP service account JSONs with literal newlines or unexpected whitespace would fail to parse, resulting in errors during file uploads to Google Drive.
Credential parsing improvements:
_save_to_google_driveinsave_file.pyto use multiple fallback strategies, including relaxed JSON parsing, whitespace stripping, double-decoding, and newline replacement, to handle a wider range of malformed or pasted service account JSONs.Testing and reliability:
test_google_drive_credential_parsing_with_control_charactersintest_save_file_component.pyto verify that service account JSONs containing literal newlines are parsed and used successfully for Google Drive uploads.test_google_drive_credential_parsing_strategiesintest_save_file_component.pyto systematically test various credential parsing strategies, including normal JSON, JSONs with control characters, and those with extra whitespace, ensuring no parsing errors occur.Summary by CodeRabbit
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.