Skip to content

Conversation

@gmorales96
Copy link
Contributor

@gmorales96 gmorales96 commented Nov 19, 2025

Summary by CodeRabbit

  • Bug Fixes

    • UUID generation now returns sanitized, URL-safe identifiers with special characters replaced for broader compatibility.
  • Tests

    • Added a test to ensure generated identifiers contain no disallowed special characters.
  • Chores

    • Version bumped to 2.1.22

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 19, 2025

Walkthrough

This PR changes uuid_field in cuenca_validations/types/helpers.py to generate a URL-safe base64 string, then sanitize it by replacing all occurrences of '-' and '_' with a single randomly chosen digit (the same digit for both replacements per generated value). The package version is bumped from 2.1.21 to 2.1.22. A new test test_sanitized_uuid in tests/test_helpers.py asserts generated UUIDs contain no - or _.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Inspect the replacement logic in cuenca_validations/types/helpers.py, focusing on the use of a single random digit for both '-' and '_' substitutions and any implications for collision or character distribution.
  • Ensure the new test tests/test_helpers.py::test_sanitized_uuid adequately asserts the absence of - and _ and consider whether additional assertions (length, allowed charset) are needed.
  • Verify the version bump in cuenca_validations/version.py.

Files to pay extra attention to:

  • cuenca_validations/types/helpers.py — sanitization uses a random single-digit replacement.
  • tests/test_helpers.py — test covers the sanitization behavior.

Possibly related PRs

  • Feature/UUID field #362 — previous change introducing the base64 URL-safe uuid_field implementation that this PR modifies by adding randomized sanitization.

Suggested reviewers

  • rogelioLpz
  • felipao-mx
  • pachCode

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: removing dash and underscore characters from UUID generation in the uuid_field function.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch sanitize-uuid-characters

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

@codecov
Copy link

codecov bot commented Nov 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (93122b7) to head (5f0584f).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #393   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           16        16           
  Lines         1405      1409    +4     
=========================================
+ Hits          1405      1409    +4     
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/helpers.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 93122b7...5f0584f. Read the comment docs.

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

Copy link
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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 93122b7 and bcba08a.

📒 Files selected for processing (3)
  • cuenca_validations/types/helpers.py (1 hunks)
  • cuenca_validations/version.py (1 hunks)
  • tests/test_helpers.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py

⚙️ CodeRabbit configuration file

**/*.py: Enforce Relative Imports for Internal Modules

Ensure that any imports referencing internal modules use relative paths. However, if modules reside in the main module directories (for example /src or /library_or_app_name) —and relative imports are not feasible—absolute imports are acceptable. Additionally, if a module is located outside the main module structure (for example, in /tests or /scripts at a similar level), absolute imports are also valid.

Examples and Guidelines:

  1. If a module is in the same folder or a subfolder of the current file, use relative imports. For instance: from .some_module import SomeClass
  2. If the module is located under /src or /library_or_app_name and cannot be imported relatively, absolute imports are allowed (e.g., from library_or_app_name.utilities import helper_method).
  3. If a module is outside the main module directories (for example, in /tests, /scripts, or any similarly placed directory), absolute imports are valid.
  4. External (third-party) libraries should be imported absolutely (e.g., import requests).

**/*.py:
Rule: Enforce Snake Case in Python Backend

  1. New or Modified Code: Use snake_case for all variables, functions, methods, and class attributes.
  2. Exceptions (Pydantic models for API responses):
    • Primary fields must be snake_case.
    • If older clients expect camelCase, create a computed or alias field that references the snake_case field.
    • Mark any camelCase fields as deprecated or transitional.

Examples

Invalid:

class CardConfiguration(BaseModel):
    title: str
    subTitle: str  # ❌ Modified or new field in camelCase

Valid:

class CardConfiguration(BaseModel):
    title: str
    subtitle: str  # ✅ snake_case for new/modified field

    @computed_field
    def subTitle(self) -> str:  # camelCase allowed only for compatibility
        return self.subtitle

Any direct use of camelCase in new or updated code outside of these exceptions should be flagged.

`*...

Files:

  • tests/test_helpers.py
  • cuenca_validations/version.py
  • cuenca_validations/types/helpers.py
🧬 Code graph analysis (1)
tests/test_helpers.py (1)
cuenca_validations/types/helpers.py (1)
  • uuid_field (13-19)
🔇 Additional comments (2)
cuenca_validations/version.py (1)

1-1: LGTM!

Version bump is appropriate for the UUID sanitization feature.

cuenca_validations/types/helpers.py (1)

13-19: Code changes are correct; the review comment's breaking change concern is unsupported by repository evidence.

The uuid_field function implementation is correct and well-tested. However, the original review comment assumes breaking impact on "existing systems, databases, or APIs" expecting URL-safe base64 format. Repository analysis reveals:

  • No production code calls uuid_field internally
  • No systems parse or validate UUID format elsewhere in the codebase
  • No database schemas or migrations reference these UUIDs
  • Tests confirm the sanitized format works as intended
  • Function is exported as public API but with no internal dependencies on the old format

The sanitization logic (replacing '-' with 'A' and '_' with 'B') does not create a breaking change within this codebase. If external consumers depend on this function, that would require verification outside this repository scope, but no evidence of internal system breakage exists.

Likely an incorrect or invalid review comment.

Copy link
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

♻️ Duplicate comments (1)
cuenca_validations/types/helpers.py (1)

14-20: Clarify/ensure the “only alphanumeric characters” invariant for the full ID

The new logic guarantees that the base64-derived portion is alphanumeric (- and _ are removed), but the returned value is prefix + sanitized. If callers pass prefixes containing non‑alphanumeric characters, the overall ID will still violate the “clean everything that isn’t alphanumeric” requirement mentioned in the earlier review.

If the intent is that the entire returned UUID is strictly [A-Za-z0-9], consider either:

  • Documenting that prefix must be alphanumeric, or
  • Sanitizing/validating prefix inside uuid_field before concatenation.
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7aea820 and 5f0584f.

📒 Files selected for processing (1)
  • cuenca_validations/types/helpers.py (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py

⚙️ CodeRabbit configuration file

**/*.py: Enforce Relative Imports for Internal Modules

Ensure that any imports referencing internal modules use relative paths. However, if modules reside in the main module directories (for example /src or /library_or_app_name) —and relative imports are not feasible—absolute imports are acceptable. Additionally, if a module is located outside the main module structure (for example, in /tests or /scripts at a similar level), absolute imports are also valid.

Examples and Guidelines:

  1. If a module is in the same folder or a subfolder of the current file, use relative imports. For instance: from .some_module import SomeClass
  2. If the module is located under /src or /library_or_app_name and cannot be imported relatively, absolute imports are allowed (e.g., from library_or_app_name.utilities import helper_method).
  3. If a module is outside the main module directories (for example, in /tests, /scripts, or any similarly placed directory), absolute imports are valid.
  4. External (third-party) libraries should be imported absolutely (e.g., import requests).

**/*.py:
Rule: Enforce Snake Case in Python Backend

  1. New or Modified Code: Use snake_case for all variables, functions, methods, and class attributes.
  2. Exceptions (Pydantic models for API responses):
    • Primary fields must be snake_case.
    • If older clients expect camelCase, create a computed or alias field that references the snake_case field.
    • Mark any camelCase fields as deprecated or transitional.

Examples

Invalid:

class CardConfiguration(BaseModel):
    title: str
    subTitle: str  # ❌ Modified or new field in camelCase

Valid:

class CardConfiguration(BaseModel):
    title: str
    subtitle: str  # ✅ snake_case for new/modified field

    @computed_field
    def subTitle(self) -> str:  # camelCase allowed only for compatibility
        return self.subtitle

Any direct use of camelCase in new or updated code outside of these exceptions should be flagged.

`*...

Files:

  • cuenca_validations/types/helpers.py
🪛 Ruff (0.14.5)
cuenca_validations/types/helpers.py

17-17: Standard pseudo-random generators are not suitable for cryptographic purposes

(S311)

@gmorales96 gmorales96 merged commit 95f8482 into main Nov 20, 2025
21 checks passed
@gmorales96 gmorales96 deleted the sanitize-uuid-characters branch November 20, 2025 17:36
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.

3 participants