-
Notifications
You must be signed in to change notification settings - Fork 20
Extended product with additional functionalities #172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Reviewer's GuideThis PR enriches the Product model with context-aware async methods by capturing the client in a private attribute, updates client methods to use pydantic’s model_validate with context, improves timezone handling in transaction requests, extends rating field validation, and adds an integration test for the new Product functionality. Class diagram for updated Product model and ProductsClientclassDiagram
class Product {
+str symbol
+str name
+str description
+str exchange
+str currency
+str isin
+str type
+str sector
+str industry
+str country
+str logo_url
+datetime inception_date
+List instrument_tags
+List child_instruments
-StakeClient _client
+model_post_init(context)
+ratings() async
+statements(start_date=None) async
}
class ProductsClient {
+get(symbol) async Product|None
+search(request) async List[Instrument]
+product_from_instrument(instrument) async Product|None
}
Product <.. ProductsClient : used by
ProductsClient o-- Product : returns
Product o-- "1" StakeClient : _client
Product o-- "*" Rating : ratings()
Product o-- "*" Statement : statements()
Class diagram for updated TransactionRecordRequestclassDiagram
class TransactionRecordRequest {
+datetime to
+datetime from_
+int limit
+datetime|None offset
}
Class diagram for updated Rating field validationclassDiagram
class Rating {
+str|None pt_prior
+str|None rating_prior
+str|None pt_current
+str|None rating_current
+pt_prior_blank_string(value, *args) classmethod
}
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @stabacco - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `stake/product.py:65` </location>
<code_context>
+ _client: "StakeClient" = PrivateAttr()
model_config = ConfigDict(alias_generator=camelcase)
+ def model_post_init(self, context: Any) -> None:
+ self._client = context.get("client")
+
+ async def ratings(self) -> "List[Rating]":
</code_context>
<issue_to_address>
No fallback if 'client' is missing from context in model_post_init.
Setting self._client to None may cause runtime errors if 'client' is missing. Raise an explicit error or provide a fallback to handle this case predictably.
</issue_to_address>
### Comment 2
<location> `stake/transaction.py:21` </location>
<code_context>
class TransactionRecordRequest(BaseModel):
- to: datetime = Field(default_factory=datetime.utcnow)
+ to: datetime = Field(default_factory=lambda *_: datetime.now(UTC))
from_: datetime = Field(
- default_factory=lambda *_: datetime.utcnow() - timedelta(days=365), alias="from"
</code_context>
<issue_to_address>
Switch to timezone-aware datetime is an improvement, but UTC must be defined.
Verify that 'UTC' is properly imported to avoid a NameError at runtime.
</issue_to_address>
### Comment 3
<location> `stake/transaction.py:23` </location>
<code_context>
- to: datetime = Field(default_factory=datetime.utcnow)
+ to: datetime = Field(default_factory=lambda *_: datetime.now(UTC))
from_: datetime = Field(
- default_factory=lambda *_: datetime.utcnow() - timedelta(days=365), alias="from"
+ default_factory=lambda *_: datetime.now(UTC) - timedelta(days=365), alias="from"
)
limit: int = 1000
</code_context>
<issue_to_address>
Same UTC concern applies to from_ default_factory.
Ensure that UTC is properly defined and accessible in this context.
</issue_to_address>
### Comment 4
<location> `stake/ratings.py:39` </location>
<code_context>
url_news: Optional[str] = None
analyst_name: Optional[str] = None
- @pydantic.field_validator("pt_prior", "rating_prior", mode="before")
+ @pydantic.field_validator("pt_prior", "rating_prior", "pt_current", "rating_current", mode="before")
@classmethod
def pt_prior_blank_string(cls, value, *args) -> Optional[str]:
</code_context>
<issue_to_address>
Validator now applies to more fields, but function name is misleading.
Consider renaming pt_prior_blank_string to better reflect that it now validates multiple fields.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| to: datetime = Field(default_factory=datetime.utcnow) | ||
| to: datetime = Field(default_factory=lambda *_: datetime.now(UTC)) | ||
| from_: datetime = Field( | ||
| default_factory=lambda *_: datetime.utcnow() - timedelta(days=365), alias="from" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): Same UTC concern applies to from_ default_factory.
Ensure that UTC is properly defined and accessible in this context.
Summary by Sourcery
Add ratings and statements endpoints to Product model, ensure Pydantic models receive client context, update default datetime handling, extend ratings validator, and include integration tests for product features
New Features:
Bug Fixes:
Enhancements:
Tests: