Update version to 2.1.33 and add FraudFundsTransferRequest, Frau…#403
Update version to 2.1.33 and add FraudFundsTransferRequest, Frau…#403rcabrera-py wants to merge 5 commits into
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughAdds three Pydantic models for fraud funds transfer flows: FraudFundsTransferRequest (with CLABE validation and concepto normalization), FraudFundsTransferAcceptedResponse (status fixed to "queued"), and FraudFundsTransferResultEvent (event_type-dependent required fields enforced by a validator). Exposes the types via package exports, adds unit tests for normalization and conditional event payload validation, and bumps package version to 2.1.32.dev2. Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #403 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 16 16
Lines 1466 1503 +37
=========================================
+ Hits 1466 1503 +37
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
41ff8e2 to
e4e497e
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cuenca_validations/types/requests.py`:
- Around line 321-326: Remove redundant custom CLABE validator: the
validate_clabe_format field validator duplicates validation provided by the
Clabe type. Delete the `@field_validator-decorated` method validate_clabe_format
and its body from the class, keep the Clabe type import and the field annotated
as clabe: Clabe so Pydantic handles format validation, and ensure no other code
references validate_clabe_format remains.
In `@cuenca_validations/version.py`:
- Line 1: The package version constant __version__ is set to '2.1.32.dev0' but
the PR objective specifies '2.1.31.dev0'; update the __version__ value in
version.py to match the PR objective (set __version__ to '2.1.31.dev0') or
alternatively update the PR description to '2.1.32.dev0' so both the code and PR
intent are consistent, ensuring the published artifact version matches the PR.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e53107db-e349-46f3-acba-81b35adf1c37
📒 Files selected for processing (4)
cuenca_validations/types/__init__.pycuenca_validations/types/requests.pycuenca_validations/version.pytests/test_types.py
d1fedb9 to
668e01a
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cuenca_validations/types/requests.py`:
- Around line 316-319: Several fields (e.g., amount, reason, request_id,
requested_by) use PEP 604 union syntax like `StrictPositiveInt | None` which
breaks on Python 3.9; replace each `X | None` with `Optional[X]` and add `from
typing import Optional` if missing, updating all nine occurrences across the
module (look for other attributes using `| None` and similar patterns) so
annotations match the project's Python 3.9 compatibility and existing style.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 7752b25b-cce1-4d6c-a1ec-f27ed8a64930
📒 Files selected for processing (2)
cuenca_validations/types/requests.pycuenca_validations/version.py
✅ Files skipped from review due to trivial changes (1)
- cuenca_validations/version.py
668e01a to
b457ec9
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
tests/test_types.py (1)
642-652: ⚡ Quick winStrengthen
conceptonormalization coverage with mixed-case input.Current assertion proves whitespace trimming, but it would still pass if lowercasing normalization regresses. Add at least one mixed-case sample to lock normalization behavior.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/test_types.py` around lines 642 - 652, The test currently checks whitespace trimming for the FraudFundsTransferRequest.concepto but doesn't assert normalization of case; update test_fraud_funds_transfer_models to include at least one mixed-case input (e.g., ' FoNdOs FraUdE ') when constructing FraudFundsTransferRequest and assert that request.concepto == 'fondos fraude' (or add a second instance with that mixed-case input and assert normalized lowercased value) to lock the expected lowercasing behavior of the concepto normalization.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cuenca_validations/types/requests.py`:
- Around line 342-365: Remove the custom `@model_validator` validate_payload on
FraudFundsTransferResultEvent and instead define two variant models (e.g.,
FraudFundsTransferSucceeded and FraudFundsTransferFailed) that set event_type =
Literal['fraud_funds_transfer.succeeded'] or
Literal['fraud_funds_transfer.failed'] and declare transaction_id and amount
(for succeeded) and reason_code and message (for failed) as required
(non-Optional) fields; then change the payload type to a
Union[FraudFundsTransferSucceeded, FraudFundsTransferFailed] and use Field(...,
discriminator="event_type") so Pydantic enforces event-specific required fields
automatically.
---
Nitpick comments:
In `@tests/test_types.py`:
- Around line 642-652: The test currently checks whitespace trimming for the
FraudFundsTransferRequest.concepto but doesn't assert normalization of case;
update test_fraud_funds_transfer_models to include at least one mixed-case input
(e.g., ' FoNdOs FraUdE ') when constructing FraudFundsTransferRequest and
assert that request.concepto == 'fondos fraude' (or add a second instance with
that mixed-case input and assert normalized lowercased value) to lock the
expected lowercasing behavior of the concepto normalization.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 1706b203-ddad-408e-adc6-04a58c63aa53
📒 Files selected for processing (3)
cuenca_validations/types/requests.pycuenca_validations/version.pytests/test_types.py
✅ Files skipped from review due to trivial changes (1)
- cuenca_validations/version.py
| @model_validator(mode='after') | ||
| def validate_payload(self) -> 'FraudFundsTransferResultEvent': | ||
| if self.event_type == 'fraud_funds_transfer.succeeded': | ||
| required = { | ||
| 'transaction_id': self.transaction_id, | ||
| 'amount': self.amount, | ||
| } | ||
| missing = [ | ||
| field for field, value in required.items() if value is None | ||
| ] | ||
| if missing: | ||
| raise ValueError( | ||
| f'{", ".join(missing)} required for succeeded event' | ||
| ) | ||
| return self | ||
|
|
||
| required = { | ||
| 'reason_code': self.reason_code, | ||
| 'message': self.message, | ||
| } | ||
| missing = [field for field, value in required.items() if value is None] | ||
| if missing: | ||
| raise ValueError(f'{", ".join(missing)} required for failed event') | ||
| return self |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
In Pydantic v2.10.5, can Field(discriminator="event_type")withLiteral-based union variants enforce event-specific required fields without a custom @model_validator?
💡 Result:
Yes, in Pydantic v2.10.5, using Field(discriminator="event_type") with Literal-based union variants automatically enforces event-specific required fields without needing a custom @model_validator [1][2]. When you define a discriminated union, Pydantic uses the discriminator field to identify which specific model in the Union should be used for validation [1]. Once the correct variant is selected, Pydantic validates the input data against that specific model's schema, which includes enforcing all required fields defined within that variant [1][2]. If the input data contains the correct discriminator tag but is missing fields required by the selected model, Pydantic will raise a ValidationError identifying the missing fields for that specific variant [1][2]. Example: from typing import Literal, Union from pydantic import BaseModel, Field class EventA(BaseModel): event_type: Literal["A"] required_a: str class EventB(BaseModel): event_type: Literal["B"] required_b: int class Container(BaseModel): event: Union[EventA, EventB] = Field(discriminator="event_type") # This will raise a ValidationError because 'required_a' is missing for EventA Container.model_validate({"event": {"event_type": "A"}}) # This will succeed Container.model_validate({"event": {"event_type": "A", "required_a": "data"}})
Citations:
- 1: https://pydantic.dev/docs/validation/latest/concepts/unions/
- 2: https://pydantic.dev/docs/validation/2.1/usage/types/unions/
🏁 Script executed:
cd cuenca_validations && cat -n types/requests.py | sed -n '300,400p'Repository: cuenca-mx/cuenca-validations
Length of output: 3850
Replace manual event payload validation with a discriminated union model.
validate_payload implements variant-required fields that Pydantic v2.10.5 already supports via Literal + discriminator-based unions. Pydantic's Field(discriminator="event_type") with separate event model variants automatically enforces event-specific required fields without custom validators, improving schema validation and error clarity.
Per the mandatory coding guideline "Use built-in Pydantic validators," replace this custom @model_validator with discriminated union variants (e.g., separate SucceededEvent and FailedEvent models) that define required fields as non-optional per event type.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@cuenca_validations/types/requests.py` around lines 342 - 365, Remove the
custom `@model_validator` validate_payload on FraudFundsTransferResultEvent and
instead define two variant models (e.g., FraudFundsTransferSucceeded and
FraudFundsTransferFailed) that set event_type =
Literal['fraud_funds_transfer.succeeded'] or
Literal['fraud_funds_transfer.failed'] and declare transaction_id and amount
(for succeeded) and reason_code and message (for failed) as required
(non-Optional) fields; then change the payload type to a
Union[FraudFundsTransferSucceeded, FraudFundsTransferFailed] and use Field(...,
discriminator="event_type") so Pydantic enforces event-specific required fields
automatically.
af8c2c7 to
4edc524
Compare
…dFundsTransferAcceptedResponse, and FraudFundsTransferResultEvent models with validation logic and tests.
…models to use union types for optional fields and update the validate_payload method to return Self.
…and FraudFundsTransferResultEvent models to use Optional for fields, removing validation logic for CLABE format.
…ired fields, and update related tests accordingly.
69cc1ef to
15736df
Compare
…dFundsTransferAcceptedResponse, and FraudFundsTransferResultEvent models with validation logic and tests.
Summary by CodeRabbit
New Features
Tests
Chores