Update ldas.py#42
Merged
Merged
Conversation
Fixed token-remove expires statement from token
Contributor
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdjusts the LDAS token handling so that only the core token value (without the leading fields and trailing character) is used after retrieval, before constructing the time series request URL. Flow diagram for updated LDAS token handlingflowchart TD
A["Retrieve raw token string<br>from HTTP response"] --> B[Replace double quotes in token]
B --> C["Split token by colon<br>using split(':')"]
C --> D[Select element index 2]
D --> E["Remove last character<br>using slice :-1"]
E --> F["Use cleaned token<br>for time_series_url requests"]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- The
token = token.split(':')[2][:-1]parsing is quite brittle (assumes a specific format and at least three segments); consider validating the format and handling unexpected cases or using a structured parser if available. - If the token format can change or include additional colons, a more robust approach (e.g., splitting once on a known prefix or using regex to extract the token value) would reduce the risk of index or slicing errors.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `token = token.split(':')[2][:-1]` parsing is quite brittle (assumes a specific format and at least three segments); consider validating the format and handling unexpected cases or using a structured parser if available.
- If the token format can change or include additional colons, a more robust approach (e.g., splitting once on a known prefix or using regex to extract the token value) would reduce the risk of index or slicing errors.
## Individual Comments
### Comment 1
<location path="src/tsgettoolbox/functions/ldas.py" line_range="1145" />
<code_context>
allow_redirects=True,
).text.replace('"', "")
-
+ token=token.split(':')[2][:-1]
time_series_url = "https://api.giovanni.earthdata.nasa.gov/timeseries"
</code_context>
<issue_to_address>
**issue (bug_risk):** The token parsing logic is brittle and may raise on unexpected formats.
This line assumes the token string always has at least three colon-separated parts and blindly strips the last character. If the format changes (different colon count, trailing whitespace, or missing colon), it may raise IndexError or corrupt the token. Please make the parsing more defensive, e.g., validate the split result, use `partition`/`rpartition`, and trim whitespace instead of slicing by index.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Fix token extraction by parsing JSON
Owner
|
Thank you! Folded this change into commits on the "develop" branch. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixed token-remove expires statement from token
Summary by Sourcery
Bug Fixes: