Guard get_shares_full against empty/missing share-count timeseries - #2898
Open
joaopedroassad wants to merge 1 commit into
Open
Guard get_shares_full against empty/missing share-count timeseries#2898joaopedroassad wants to merge 1 commit into
joaopedroassad wants to merge 1 commit into
Conversation
Collaborator
Example? |
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.
Summary
TickerBase.get_shares_fullreadsjson_data["timeseries"]["result"]and then indexesshares_data[0]with no guard. When Yahoo returns a 200 whose share-count timeseries envelope has an emptyresult([]), anullresult, or omitstimeseriesentirely (thefinanceerror envelope), this raises a rawIndexError/TypeError/KeyErrorthat leaks straight to the caller and ignoreshide_exceptions.resultis the common case: symbols with no share-count history (a lot of non-US tickers, ETFs, indices) come back as{"timeseries": {"error": null, "result": []}}, soshares_data[0]hitsIndexError: list index out of range.get_shares_full()call.Quote.sharescallsget_shares_fullinternally to populate thesharescomplementary field, so the same exception can take down.infofor the whole ticker.resultdefensively and returnNonewhen it's empty, exactly like the existingif "shares_out" not in shares_data[0]: return Noneexit right below it. Every other failure path in this function already returnsNone.This is the same class of empty/malformed-timeseries guard as #2877 (Complementary info: guard against empty or missing timeseries result), which fixed the identical
json_result["result"][0]pattern inquote.py. This is the next-door site inbase.pythat reads the same share-count timeseries shape and was still unguarded.Testing
Ran in a fresh venv with an editable install:
Red -> green on the new test:
Adjacent complementary-info guard tests still pass:
Lint / compile clean on changed files:
The new test is fully mock-based (patches
_data.cache_get, sets_tzto skip the network tz lookup), so it needs no network. It covers the four failing shapes (empty list, missingresult, nullresult, missingtimeseries) plus a happy path that still returns a populated Series.