Skip to content

Update version to 2.1.33 and add FraudFundsTransferRequest, Frau…#403

Open
rcabrera-py wants to merge 5 commits into
mainfrom
feat/add-transfer-fraud-models
Open

Update version to 2.1.33 and add FraudFundsTransferRequest, Frau…#403
rcabrera-py wants to merge 5 commits into
mainfrom
feat/add-transfer-fraud-models

Conversation

@rcabrera-py
Copy link
Copy Markdown
Contributor

@rcabrera-py rcabrera-py commented May 15, 2026

…dFundsTransferAcceptedResponse, and FraudFundsTransferResultEvent models with validation logic and tests.

Summary by CodeRabbit

  • New Features

    • Added fraud funds transfer request, queued acceptance response, and result event types
    • Result events validate differently for succeeded vs failed outcomes
  • Tests

    • Added tests covering new models, normalization of transfer fields, and succeeded/failed event validation
  • Chores

    • Version bumped to 2.1.32.dev2

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 15, 2026

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Adds 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

  • felipao-mx
  • rogelioLpz
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ⚠️ Warning The title mentions updating version to 2.1.33, but the actual version change is to 2.1.32.dev2. Additionally, the title is truncated and doesn't fully convey the complete model names being added. Update the title to accurately reflect the version change to 2.1.32.dev2 and ensure it fully describes the models being added without truncation.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/add-transfer-fraud-models

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (e1e0338) to head (15736df).

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     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
cuenca_validations/types/__init__.py 100.00% <ø> (ø)
cuenca_validations/types/queries.py 100.00% <100.00%> (ø)
cuenca_validations/types/requests.py 100.00% <100.00%> (ø)
cuenca_validations/version.py 100.00% <100.00%> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e1e0338...15736df. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rcabrera-py rcabrera-py force-pushed the feat/add-transfer-fraud-models branch from 41ff8e2 to e4e497e Compare May 15, 2026 18:36
@rcabrera-py rcabrera-py changed the title Update version to 2.1.31.dev0 and add FraudFundsTransferRequest, Frau… Update version to 2.1.32 and add FraudFundsTransferRequest, Frau… May 15, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9708d0b and e4e497e.

📒 Files selected for processing (4)
  • cuenca_validations/types/__init__.py
  • cuenca_validations/types/requests.py
  • cuenca_validations/version.py
  • tests/test_types.py

Comment thread cuenca_validations/types/requests.py Outdated
Comment thread cuenca_validations/version.py Outdated
@rcabrera-py rcabrera-py force-pushed the feat/add-transfer-fraud-models branch from d1fedb9 to 668e01a Compare May 15, 2026 19:18
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between d1fedb9 and 668e01a.

📒 Files selected for processing (2)
  • cuenca_validations/types/requests.py
  • cuenca_validations/version.py
✅ Files skipped from review due to trivial changes (1)
  • cuenca_validations/version.py

Comment thread cuenca_validations/types/requests.py Outdated
@rcabrera-py rcabrera-py force-pushed the feat/add-transfer-fraud-models branch from 668e01a to b457ec9 Compare May 15, 2026 19:29
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/test_types.py (1)

642-652: ⚡ Quick win

Strengthen concepto normalization 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

📥 Commits

Reviewing files that changed from the base of the PR and between b457ec9 and 63b5848.

📒 Files selected for processing (3)
  • cuenca_validations/types/requests.py
  • cuenca_validations/version.py
  • tests/test_types.py
✅ Files skipped from review due to trivial changes (1)
  • cuenca_validations/version.py

Comment on lines +342 to +365
@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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

🧩 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:


🏁 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.

@rcabrera-py rcabrera-py force-pushed the feat/add-transfer-fraud-models branch from af8c2c7 to 4edc524 Compare May 15, 2026 21:55
…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.
@rcabrera-py rcabrera-py force-pushed the feat/add-transfer-fraud-models branch from 69cc1ef to 15736df Compare May 25, 2026 18:24
@rcabrera-py rcabrera-py changed the title Update version to 2.1.32 and add FraudFundsTransferRequest, Frau… Update version to 2.1.33 and add FraudFundsTransferRequest, Frau… May 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant