Remove dict and use yfinance data for company mapping instead#312
Remove dict and use yfinance data for company mapping instead#312zaynfuture wants to merge 1 commit intoTauricResearch:mainfrom
Conversation
Summary of ChangesHello @zaynfuture, 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 refactors the company name resolution logic within the 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. 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
|
There was a problem hiding this comment.
Code Review
This pull request aims to improve robustness and maintainability by replacing a hardcoded ticker-to-company mapping with dynamic data fetching from yfinance. However, a critical command injection vulnerability has been identified in tradingagents/dataflows/reddit_utils.py. This vulnerability arises because user-supplied input is passed to the yfinance library without proper sanitization, which could lead to remote code execution. It is crucial to remediate this by validating user input before it is processed by the external library. Additionally, the review suggests fixing a bug that creates duplicate search terms and improving error handling by logging exceptions instead of silently ignoring them.
| else: | ||
| search_terms = [ticker_to_company[query]] | ||
| try: | ||
| info = yf.Ticker(query).info or {} |
There was a problem hiding this comment.
The query parameter, which can be controlled by the user, is passed directly to the yf.Ticker() constructor. Certain versions of the yfinance library are susceptible to OS command injection vulnerabilities via the ticker symbol. An attacker could potentially inject malicious commands by providing a specially crafted query string, leading to arbitrary command execution on the server. It is recommended to sanitize the query input by validating it against a known list of safe ticker symbols or by using a regex to allow only alphanumeric characters.
| if company_name: | ||
| search_terms.insert(0, company_name) | ||
|
|
||
| search_terms.append(query) |
There was a problem hiding this comment.
The ticker symbol (query) is added to search_terms twice. It's first added at line 67, and then again at this line. This is redundant and leads to search_terms containing duplicate entries (e.g., ['Apple Inc.', 'AAPL', 'AAPL'] if the company name is found). You can safely remove this line to fix the duplication.
| except Exception: | ||
| company_name = None |
There was a problem hiding this comment.
It's good practice to log exceptions, even if you are handling them gracefully. Silently catching all exceptions can hide underlying issues with the yfinance API, network connectivity, or invalid tickers that don't behave as expected. Consider printing a warning message to make debugging easier in the future.
| except Exception: | |
| company_name = None | |
| except Exception as e: | |
| print(f"Warning: Could not fetch company name for ticker '{query}' from yfinance: {e}") | |
| company_name = None |
When I tested using TEM, I found that the tool analyzed TEM as TSM. After investigating, I learned that this behavior was controlled by the ticker_to_company logic. Therefore, this part has been replaced with company name resolution using open-source data from yfinance.